472,780 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

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
5 7109
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matthias Teege | last post by:
Moin, I'm new to python. I try to build a "easy" search interface to a database table in python. I have a input string like this: "name=matthias;count>10" or this "location!=thisone". From this...
4
by: beliavsky | last post by:
The code for text in open("file.txt","r"): print text.replace("foo","bar") replaces 'foo' with 'bar' in a file, but how do I avoid changing text inside single or double quotes? For making...
28
by: David Rubin | last post by:
I looked on google for an answer, but I didn't find anything short of using boost which sufficiently answers my question: what is a good way of doing string tokenization (note: I cannot use boost)....
10
by: Alex | last post by:
I'm looking for a fast way to split a string into individual tokens. The typical format of the string is token1|token2|token3|...|tokenN| and the number of tokens varies (which is why i use a...
4
by: Kelvin | last post by:
hi: in C, we can use strtok() to tokenize a char* but i can't find any similar member function of string that can tokenize a string so how so i tokenize a string in C++? do it the C way? ...
9
by: shyam | last post by:
Hi All Here is a program which basically tokenizes a string based on space seperation. But it does not run bcoz i am directly trying to manuplate the string. I cannot use standard string...
20
by: bubunia2000 | last post by:
Hi all, I heard that strtok is not thread safe. So I want to write a sample program which will tokenize string without using strtok. Can I get a sample source code for the same. For exp:...
2
by: askalottaqs | last post by:
there's in maya's scripting language mel, called tokenize, you simply tokenize("string i want to tokenize"," ",bufferArray) which will fill the fufferArray wih the first string tokenized accorfing...
8
by: Mugunth | last post by:
I'm writing a search engine crawler for indexing local files in C# My dataset is about 38000 XML files and as of now, I've successfully parsed the file, and tokenized it. But, it's surprising to...
4
by: Phantom | last post by:
I'm wondering if anyone knows a trick to iterate a FLWR expression across a literal string that is delimited by spaces. e.g. for $x in ("apple orange banana blueberry") obviously, this...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.