467,915 Members | 1,162 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

String Tokenize

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

Thanks
Nov 17 '05 #1
  • viewed: 6801
Share:
5 Replies
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
Hi
I try to read in a line from text file, and how can I tokenize the line?

Thanks

Nov 17 '05 #2
Lam

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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eU**************@TK2MSFTNGP10.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
Hi
I try to read in a line from text file, and how can I tokenize the line?

Thanks


Nov 17 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:el**************@TK2MSFTNGP14.phx.gbl...

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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:eU**************@TK2MSFTNGP10.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Lam" <ja**********@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP09.phx.gbl...
> Hi
> I try to read in a line from text file, and how can I tokenize the
> line?
>
> Thanks
>
>



Nov 17 '05 #4

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u4**************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #5
Lam
Thanks guys..it seem to be working

"Mythran" <ki********@hotmail.comREMOVETRAIL> wrote in message
news:ei**************@TK2MSFTNGP10.phx.gbl...

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:u4**************@TK2MSFTNGP14.phx.gbl...
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

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Matthias Teege | last post: by
4 posts views Thread by beliavsky | last post: by
28 posts views Thread by David Rubin | last post: by
10 posts views Thread by Alex | last post: by
4 posts views Thread by Kelvin | last post: by
9 posts views Thread by shyam | last post: by
20 posts views Thread by bubunia2000 | last post: by
2 posts views Thread by askalottaqs | last post: by
8 posts views Thread by Mugunth | last post: by
4 posts views Thread by Phantom | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.