String\Delimiter

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
 
G

Göran Andersson

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top