Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6178811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:31:46+00:00 2026-05-24T00:31:46+00:00

I apologize for this newbie question, but I’m looking for a simple solution. I

  • 0

I apologize for this newbie question, but I’m looking for a simple solution.
I want to write a function that will return a datatable.
Like this:

public static DataTable DataTableCommaReplce(DataTable dt){..}

The function will check each data in DataTable.
If data contained one or more commas, the function will make that data in double quote.
For Example:

you,me⇒"you,me"

What’s the best way to write this function?
Can any body help me?


I had solved with this code, but I want more simple solution.
If possible, I want no looping.

public static DataTable DataTableCommaReplce(DataTable dt)
        {
            int col = dt.Columns.Count;
            foreach (DataRow dr in dt.Rows)
            {
                for (int i = 0; i < col; i++)
                {
                    if (dr[i].ToString().IndexOf(",") > 0)
                    {
                        dr[i] = "\"" + dr[i].ToString() + "\"";
                    }
                }
            }
            return dt;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:31:46+00:00Added an answer on May 24, 2026 at 12:31 am

    This should work:

    public static DataTable DataTableCommaReplce(DataTable dt) {
        foreach (DataRow row in dt.Rows) {
            foreach (DataColumn col in dt.Columns) {
                string s = row[col] as string;
                if (s != null) {
                    if (s.Contains(',')) {
                        row[col] = string.Format("\"{0}\"", s);
                    }
                }
             }
        }
        return dt;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize that this isn't a question on how to use Mathematica, but rather
I apologize if this is a little simple, but I've been googleing and googleing
i'm a bit new to JQuery and ajax, so i apologize if this is
This is my first time trying Rcpp and this very simple problem is giving
Apologies, but I'm a newbie at Flot. I'd like to display my data in
I apologize if this has been answered, I've searched for some time and could
Possible Duplicates: Reference - What does this symbol mean in PHP? In, PHP, what
Apologies if this is a FAQ, I did not find it anywhere. It is
I am an absolute newbie without even a computer science background. I am just
Is it possible to have several command prompts running simultaneously and switch between them,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.