• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

StringReplace

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
Is there a good StringReplace library? couldn't find one on google, and i found Nestharus's FindString library on the hive but i'd need to edit it to make a StringReplace lib
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Doesn't FindString return the integer where the string starts?
If so, you can concatenate substrings, which is the same as replacing it.

So, for example, if you have the string "TheSpoonAbides" and you wish to replace "Spoon" with "Dude", then you can use FindString to find "Spoon".
It will tell you that it starts at location 3.
So you can do (substring from 0 to 3) + "Dude" + SubString(3 + length of "Spoon" to length of string).
SubString from 0 to 3 is "The"
+ "Dude" = "TheDude"
+ SubString from 8 to 14 = "TheDudeAbides".

I hope this made sense :D.

Edit: you can add this function below "FindString", or in a separate library that needs FindString (the shortest library ever, then)

JASS:
function ReplaceString takes string str, string strToFind, integer start, string strToReplace returns string
    local integer i = FindString(str, strToFind, start)
    return SubString(str, start, i) + strToReplace + SubString(str, i+StringLength(strToFind), StringLength(str))
endfunction
 
Status
Not open for further replies.
Top