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?
Jul 09 '10 at 12:55 PM
Jul 09 '10 at 01:33 PM
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;
Jul 09 '10 at 12:56 PM
Jul 09 '10 at 01:35 PM
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
LastIndexOf(" "); is just what I was looking for! Thanks
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.
Jul 09 '10 at 01:32 PM
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
Once you sign in you will be able to subscribe for any updates here
Answers and Comments
The best place to ask and answer questions about development with Unity. Check out our FAQ for more information.
To help users post good questions and use the site effectively we have posted a tutorial video. Please check it out.
asked: Jul 09 '10 at 12:55 PM
Seen: 3345 times
Last Updated: Jul 09 '10 at 01:33 PM
how to display a long string sentence by sentence instead of character by character?
how can i split a word to individual letters..??
how to get words of a string
What is the maximum byte length of Application.ExternalCall? (and oh yea, it doesn't escape strings correctly)
Shot Counter Question
Is it normal for string operations to be very expensive on the iPhone?
Combining several strings into a single one?
Finding the length of a string
Where can I find a list of characters sent from when pressing key? Examples of characters are: "\b" "\n"
Seperate large numbers with comma