String Tokenize

  • Thread starter Thread starter Lam
  • Start date Start date
Lam,

If you have just one character that you can split the string on, just
use the Split method on the string instance. If you have more complex
tokenization requirements, then use a regular expression.

Hope this helps.
 
I am new to c# and I am not sure how to use regular expression
I have the line like this

"C 07/18/05 12:01 18002236481 00:04:01 805 130"

how can I put each one into different string variables?
maybe you can give me some hints ?

Thanks a lot


Nicholas Paldino said:
Lam,

If you have just one character that you can split the string on, just
use the Split method on the string instance. If you have more complex
tokenization requirements, then use a regular expression.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lam said:
Hi
I try to read in a line from text file, and how can I tokenize the line?

Thanks
 
Lam,

Is your delimiter the space character? If so, you can just call the
Split method, like so:

// Split on the space character.
// Assume val stores the string.
string[] strings = val.Split(new char[]{' ', '\t'}, false);

In .NET 2.0, it should be noted that false should be replaced with
StringSplitOptions.None (the overload with the boolean parameter is marked
as obsolete).


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lam said:
I am new to c# and I am not sure how to use regular expression
I have the line like this

"C 07/18/05 12:01 18002236481 00:04:01 805 130"

how can I put each one into different string variables?
maybe you can give me some hints ?

Thanks a lot


in
message news:[email protected]...
Lam,

If you have just one character that you can split the string on, just
use the Split method on the string instance. If you have more complex
tokenization requirements, then use a regular expression.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lam said:
Hi
I try to read in a line from text file, and how can I tokenize the
line?

Thanks
 
Nicholas Paldino said:
Lam,

Is your delimiter the space character? If so, you can just call the
Split method, like so:

// Split on the space character.
// Assume val stores the string.
string[] strings = val.Split(new char[]{' ', '\t'}, false);

In .NET 2.0, it should be noted that false should be replaced with
StringSplitOptions.None (the overload with the boolean parameter is marked
as obsolete).

To me, it looks like a fixed length or tab-delimited file. But more lines
would be needed to say one way or the other ;)

Thought I'd point that out ;)


Mythran
 
Thanks guys..it seem to be working

Mythran said:
message news:[email protected]...
Lam,

Is your delimiter the space character? If so, you can just call the
Split method, like so:

// Split on the space character.
// Assume val stores the string.
string[] strings = val.Split(new char[]{' ', '\t'}, false);

In .NET 2.0, it should be noted that false should be replaced with
StringSplitOptions.None (the overload with the boolean parameter is marked
as obsolete).

To me, it looks like a fixed length or tab-delimited file. But more lines
would be needed to say one way or the other ;)

Thought I'd point that out ;)


Mythran
 
Back
Top