Lugoun posted this handy script in the Helpful Scripts thread in the official forums. It allows you to do a find and replace on a string. Just pass in the text you want to perform the find and replace on, the string to find and the string you want to replace it with. His script is below and I've added comments.
// Returns a string based on sStartString where sCurrentWord is replaced by sNewWord
string FindReplaceSubString(string sStartString, string sCurrentWord, string sNewWord)
{
int nLength = GetStringLength(sStartString);
int nCurrSubLoc = FindSubString(sStartString, sCurrentWord);
string sLeftSide = GetStringLeft(sStartString, nCurrSubLoc);
int nCurrentLength = GetStringLength(sCurrentWord);
int nLeftSideLength = nCurrSubLoc + nCurrentLength;
int nRightSideLength = nLength - nLeftSideLength;
string sRightSide = GetStringRight(sStartString, nRightSideLength);
string sNewString = sLeftSide + sNewWord + sRightSide;
return sNewString;
}
So for instance, you can do a call like this:
string sStartString = "the quick brown fox is quick";
string sNewString = FindReplaceSubString(sStartString, "quick", "slow");
Which would assign sNewString a value of "the slow brown fox is slow".
Recent comments
11 weeks 6 days ago
11 weeks 6 days ago
12 weeks 2 hours ago
17 weeks 6 days ago
18 weeks 2 days ago
34 weeks 5 days ago
35 weeks 11 hours ago
39 weeks 1 day ago
39 weeks 2 days ago
42 weeks 2 days ago