hi all,

I am having a string. Now i need to get the last word in that string.


string text = "Hello.. how are you";

Now i need to get 'you' from that string. can anyone help me..

Thank you.

if it is separated by a space then split the string as

string text = "Hello.. how are you";
String[] splitText=text.Split(' ');

this will solve your problem

Hello niths,
Words are separated by spaces. Find where the first space occur. The characters preceding the space will give you the word.
Since you want the last word of the string look for the space from the end.

You are fast in typing.

This is another solution:

string yourWord = text.SubString(text.LastIndexOf(" "), text.Lenght - text.LastIndexOf(" "));

hey thanks abelLazm... that solved my problem.. :)