Use
String.Split()
.
As an example, if you called this on "51.103 1.800" :
string data = "51.103 1.800";
string[] lines = data.Split();
Now
lines
would have 2 items,
lines[0]
would be "51.103" and
lines[1]
would be "1.800".
*Update*
----------
[Thanks to John]
Note how I don't pass any parameter to
Split
. What happens is that it will split based on any white space character (tab, space, multiple spaces, newline etc.)
If you specifically want to split on a single space, do it as follows:
data.Split(' ');
*Another Update *
--------------------
[Thanks to GenJerDan]
If you want to be sure that the returned array won't have any empty strings, you can use an overload that takes a
StringSplitOptions
argument.
Example:
string[] lines = data.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
You cannot take advantage of the params feature in this overload so you need to use actual array creation syntax for the first parameter.