O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

1.7. The string Type

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,

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required