What I am aimed to do is this:
Instead of: I;am;writing;in;C#
I want the output to be:
I
am
writing
in
C#
- Rukia
Instead of: I;am;writing;in;C#
I want the output to be:
I
am
writing
in
C#
- Rukia
Know the answer? Post it. Somebody with the same question will find it here.
AnttiRank #9,295 · 208 pointsPosted Dec 20, 2005, 12:01 AM EST
Hmm, You can do this much much easier than with this tokenizer class. String class has its own splitter, called Split. It takes char array as a parameter, and it should contain all the delimiters wished to use for splitting (tokenising) the string.
Here's the example program:
using System; using System.Collections.Generic; using System.Text; namespace TokeniseText { class Program { static void Main(string[] args) { string message = "I;am;writing;in;C#"; //split with one delimiter string[] lines = message.Split(';'); foreach (string line in lines) { Console.WriteLine(line); } Console.WriteLine(); //or string message2 = "I;am;writing;in;C#.Isn't.it.nice?;Very."; //you can add several different delimiters here //and split the string with all of them at the same time char[] delimiters = new char[] { ';', '.' }; string[] lines2 = message2.Split(delimiters); foreach (string line in lines2) { Console.WriteLine(line); } } } }Result:
I
am
writing
in
C#
I
am
writing
in
C#
Isn't
it
nice?
Very
Press any key to continue . . .
Edit: single delimiter line simplified
Tom Diann16 pointsPosted Dec 20, 2005, 12:09 AM EST
AnttiRank #9,295 · 208 pointsPosted Dec 20, 2005, 9:35 PM EST
>>use string.Split(char c) function
Yeah, because the method is
String.Split(params char[]), you can also give just a char as a parameter.Rukia3 pointsPosted Dec 21, 2005, 8:23 PM EST
tvc19833 pointsPosted Jan 8, 2006, 7:00 PM EST