Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C# have a String Tokenizer like Java's?

Tags:

string

c#

parsing

I'm doing simple string input parsing and I am in need of a string tokenizer. I am new to C# but have programmed Java, and it seems natural that C# should have a string tokenizer. Does it? Where is it? How do I use it?

like image 805
andrewrk Avatar asked Sep 16 '08 08:09

andrewrk


People also ask

What is the do in C?

The do-while statement lets you repeat a statement or compound statement until a specified expression becomes false.

What does |= mean in C?

The ' |= ' symbol is the bitwise OR assignment operator.


1 Answers

You could use String.Split method.

class ExampleClass {     public ExampleClass()     {         string exampleString = "there is a cat";         // Split string on spaces. This will separate all the words in a string         string[] words = exampleString.Split(' ');         foreach (string word in words)         {             Console.WriteLine(word);             // there             // is             // a             // cat         }     } } 

For more information see Sam Allen's article about splitting strings in c# (Performance, Regex)

like image 101
Davy Landman Avatar answered Sep 30 '22 17:09

Davy Landman