Help parsing string

  • Thread starter Thread starter LEM
  • Start date Start date
L

LEM

Hi all,

I'm new to C# and I'm trying to parse a string into several variables.
I used to do this in C with sscanf, but I don't know how to do it in C#.

Basically I have this.

String cBuffer = "abc|defgh|ijk";
String cPart1,cPart2,cPart3;

After calling my function, I should get
cPart1 = abc
cPart2 = defgh;
cPart3 = ijk;

I use | as a separator.

Is there a fast way of doing that in C#?

Thanks!
 
LEM said:
I'm new to C# and I'm trying to parse a string into several variables.
I used to do this in C with sscanf, but I don't know how to do it in C#.

Basically I have this.

String cBuffer = "abc|defgh|ijk";
String cPart1,cPart2,cPart3;

After calling my function, I should get
cPart1 = abc
cPart2 = defgh;
cPart3 = ijk;

I use | as a separator.

Is there a fast way of doing that in C#?

cBuffer.Split('|') will return an array of 3 strings etc.

-- Barry
 
Back
Top