December 2001
Intermediate to advanced
416 pages
8h 16m
English
Once we have read a line of text, we need to separate it into the individual words. The simplest method of doing that is to use the Split() method of string—for example,
string text_line;
string [] text_words;
while (( text_line = freader.ReadLine() ) != null )
{
text_words = text_line.Split( null );
// ...
}
Split() returns an array of string elements separated by a set of characters indicated by the user. If Split() is passed null, as it is in our example, it separates the elements of the original string using white space, such as a blank character or a tab. For example, the string
A beautiful fiery bird, he tells her, magical but untamed.
is split into an array of 10 string elements. Three of them, however—bird,
Read now
Unlock full access