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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
tvc1983Posted Jan 9, 2006, 12:00 AM
RukiaPosted Dec 22, 2005, 1:23 AM
AnttiPosted Dec 21, 2005, 2:35 AM
>>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.Tom DiannPosted Dec 20, 2005, 5:09 AM
AnttiPosted Dec 20, 2005, 5:01 AM
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