Hi John,
Split deals with characters as a parameter not a string that is why you
use single quotes (for characters) instead of double quotes which are used
for strings.
This would parse the last name because the Split function is iterating
through the characters in the string until it finds an instance of the
character you wanted to split on, it then takes whatever is infront of that
character (which could be an empty string) as one element of the array, moves
past the split character and keeps looking for the next instance of the split
character so in your case it would be:
After the trim operation you will have "Edward C Koop"
-1st split character found
"Edward C Koop"
---------^ -> "Edward" is first element in the list
-2nd instance of split character found
"Edward C Koop"
-----------^ -> "C" is the second element in the list
-End of string reached
"Edward C Koop"
------------------^ -> "Koop" is third element in the list
Hope that helps
Mark R Dawson
http://www.markdawson.org
Edward
"John Salerno" wrote:
This is an example in the book I'm reading:
string fullName = " Edward C Koop ";
fullName = fullName.Trim();
string[] names = fullName.Split(' ');
string firstName = names[0]; // Edward
Two questions about this:
1. Why do you use single quotes with Split() instead of double? Is this
necessary?
2. Would this parse the last name, since Trim() took out the trailing
space? Isn't Split() only looking for spaces following the separate
elements (words) of the string?