• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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