I would only want to replace the first "cat", not the second. Split/join will replace both. Just wondering if there's a way. (p.s. actionscript 2, so cant do "replace" I dont think)
I just made a new function for Strings, replaceWord, just like String.substr, String.split, String.join, etc.
The code might look shockingly huge, but what it does, is that it analyzes each letter in the string, and then if one letter is the same as the first letter of the new word, then another code is executed, which then checks if all the letters match with the new word, if that's true as well, then the index of that word is saved inside an Array, and all other matches are saved in that Array as well. Once the analyzation is over, we check if there were found any matches, and if there were, then return the whole String, with the desired position of the found word, replaced with the new word (this is done by using String.substring, which takes out a portion of your string with the specified indexes, by this, we can take the first part of the String, before the occurred word, add the new word after that, and then add the rest of the String after the end of the found word).
The first parameter is the word you wish to change, the second is the word you wish to replace to, and the third one is which word in the String you want to replace, for instance, in myText, there are 2 occurrances of "cat", and in this case, I replaced the first occurrance, whose index is 0, in the indexes array.
Try changing 0 to 1, and see the difference
Hope this helps
17 Years old boy, who loves the Computer Technology
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
Well, no yours is better! With mine I can only change the first instance (unless i use lastIndexOf), but for something in the middle, or for users choice, yeah yours is awesome! Lol Im just giving you hell for being such a brainiac! (thats a compliment of course!)