Remove the last word from a string

Is there some code like this:

var newStr = str.Substring(0, str.length-1);

That will allow you to remove the last whole word instead of one character?

This should do it:

var newStr = str.Replace("yourWord", "");


var newStr : String;
var idx = str.LastIndexOf(" ");
if (idx > -1)
    newStr = str.Remove(idx);
    newStr = str;

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.