String\Delimiter

  • Thread starter Thread starter gh
  • Start date Start date
G

gh

I have a string that is delimited with commas. Is there a function in
C# that will break apart the string at each comma, so I can copy the
value to a var? This is a .net v1.1.4 app.


TIA
 
gh said:
I have a string that is delimited with commas. Is there a function in
C# that will break apart the string at each comma, so I can copy the
value to a var? This is a .net v1.1.4 app.

The easiest way would be to use the Split method of the string class:

string[] subStrings = commaDelimitedString.Split(',');

Often a string is actually delimited with a comma and a space, in that
case you would want to split on the string ", " instead:

string[] subStrings = commaDelimitedString.Split(new string[]{", "},
StringSplitOptions.None);

If the space after the comma is optional, you would use two delimiter
strings:

string[] subStrings = commaDelimitedString.Split(new string[]{", ",
","}, StringSplitOptions.None);
 
Back
Top