c# parsing


  • hello, just checking if anyone knows a simple way to parse out the following in c# before i try to hack up some ugly code to manually do this:

    "A", "B", "C"

    into A, B, C.... A, B, C are strings that can have a comma in it.

    Friday, January 04, 2013 6:42 PM


All replies

  • Tell me if I am wrong, but if you want to to make a very simple string that hold all values + comma you can do it in this way which is most simple:

    string a = "A";
    string b = "B";
    string c = "C";
    string comma = ",";
    string print = a + comma + b + comma + c;

    Microsoft Student Parnter Microsoft Technology Associate

    Friday, January 04, 2013 6:47 PM
  • If this is in a CSV file, you can use the TextFieldParser class to do this:

    This class is built in, and handles nested commas within your quoted strings, etc.

    Reed Copsey, Jr. -
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Proposed as answer by servy42 Friday, January 04, 2013 7:37 PM
    • Marked as answer by Nehemiah Willis Monday, January 07, 2013 6:16 PM
    Friday, January 04, 2013 7:07 PM
  • Willis :

    Does this help with parsing ?

               string[] arr = { "A", "B", "C" };
               var result = new String(string.Join(",",arr).ToCharArray());

    Saturday, January 05, 2013 3:36 AM
  • thanks Reed, TextFieldParser class worked.

    @Venkat786, I'm trying to split out a comma separated, quoted fields, not join them them back together.  I tried doing split but it messes up if a field has a comma within.

    Monday, January 07, 2013 6:20 PM