Spliting

G

Guest

Hello all,

I was wondering if someone could give me a quick bit of help!

I have a string such as the below

name$id|type,name$id|type,name$id|type

that I split on the , to create

name$id|type
name$id|type
name$id|type

Whats the best way to then get at each individual element, such as name etc?
Any neat liitle methods?

Thanks,

Jon
 
K

Karl Seguin

I don't know what ur doing, but there might be a better way...joining
strings with separators tends to not be the best solution.

That said, you really have 2 choices. Split again or use a regular
expression.

Karl
 
D

dan

Jon,

Here's a "split again" way of doing it:

char [] cSep1 = new char [] { ',' };
char [] cSep2 = new char [] { '$', '|' };
string sText = "name$id|type,name$id|type,name$id|type";
string [] split1;
string [] split2;

split1 = sText.Split( cSep1 );
foreach( string s in split1 )
{
split2 = s.Split( cSep2 );
Console.WriteLine( string.Format( "Name: {0} Type: {1}", split2[0],
split2[2] ) );
}

Dan
 

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

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top