Nestharus
o-o
- Reaction score
- 83
JASS:
library AddRepeatedString
//adds a string to another string in spaced intervals
//call AddRepeatedString(1234567,"-",3,0) -> 123-456-7
function AddRepeatedString takes string s, string str, integer spacing, integer start returns string
local integer i = StringLength(s)
local integer p = 1
loop
exitwhen p*spacing+start>=i
set s = SubString(s,0,p*spacing+p+start-1)+str+SubString(s,p*spacing+p+start-1,StringLength(s))
set p=p+1
endloop
return s
endfunction
endlibrary
JASS:
library RemoveString
//removes all traces of a string from another string
//0 means remove all
//call RemoveString("123123","12",0,0) -> 33
//call RemoveString("123-123","-",0,0) -> 123123
//maxRemove is useful for removing an instance of a string once
//call RemoveString("-load mau3-load -ffff","-load ",1,0) -> "mau3-load -ffff"
function RemoveString takes string s, string str, integer maxRemove, integer start returns string
local integer p = StringLength(str)
local integer i = StringLength(s)
local integer m = start
if (0<i) then
if (0==maxRemove) then
set maxRemove=-1
endif
loop
exitwhen m==i or 0==maxRemove
if (str==SubString(s,m,m+p)) then
set maxRemove = maxRemove - 1
set s=SubString(s,0,m)+SubString(s,m+p,StringLength(s))
set i=i-1
else
set m=m+1
endif
endloop
endif
return s
endfunction
endlibrary
JASS:
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|"+RemoveString("-load mau3-load -ffff","-load ",1,0)+"|")
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"|"+RemoveString("-123-456-","-",0,0)+"|")
call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,AddRepeatedString("123456712345671234567","-",4,0))