Hi
I try to read in a line from text file, and how can I tokenize the line?
Thanks 5 7152
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
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
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 > >
"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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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)....
|
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...
|
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?
...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |