none
c# parsing

    Question

  • 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

Answers

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;
    
    Console.WriteLine(print);



    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: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx

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


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

    Friday, January 04, 2013 7:07 PM
    Moderator
  • Willis :

    Does this help with parsing ?

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

    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