When you say you want to remove the first word, do you mean you want myName
to equal "Smith Curtis"? If that's the case, then you'd have to reassign
the results of SubString, since Strings are immutable (you can reassign but
not change the contents of the memory it is referencing).
So you've got:
String myName = "John Smith Curtis";
System.Diagnostics.Debug.WriteLine(myName.Substrin g(0, myName.IndexOf("
")));
System.Diagnostics.Debug.WriteLine(myName.Substrin g(myName.IndexOf(" ") +
1)); // Warning: this would break if myName == "John " or has no spaces but
for your sample, it works
"shapper" <md*****@gmail.comwrote in message
news:11*********************@i15g2000cwa.googlegro ups.com...
Hello
I have the following string:
myName = "John Smith Curtis"
I want to get the first word, i.e. "John", which means I want to get
everything from the start to the first space.
I know I should use Substring but I don't know what to do to remove the
first word.
Thanks,
Miguel