- Home /
Answer by Mike 3 · Jul 09, 2010 at 12:56 PM
This should do it:
var newStr = str.Replace("yourWord", "");
Edit:
var newStr : String;
var idx = str.LastIndexOf(" ");
if (idx > -1)
newStr = str.Remove(idx);
else
newStr = str;
Thanks, but I need the code to be generic so that it removes the last word no matter what the word is. Also, the word might be found more than once in a string and I wouldn't want to remove them all!
In that case i'm editing the question and then my answer so it makes more sense
Answer by Jessy · Jul 09, 2010 at 01:32 PM
Given your comment to Mike, here's a solution.
Use Remove along with LastIndexOf(" "), to get the index of the last space. We will need more information from you if finding a space isn't a good enough solution for you to find the final word.
Your answer
Follow this Question
Related Questions
Split string, add action to every word 1 Answer
how to display a long string sentence by sentence instead of character by character? 1 Answer
RemoveAt(T[]codes, T code) doesnt work 1 Answer
how can i split a word to individual letters..?? 2 Answers
In an Input Field, I want to remove the whole word, if my user deletes on character of it 1 Answer