Warcraft III resources & community, 2003–2006 · archived

StringRemoveString

not rated
Submitted by fuglyText Parsing0 downloads
Very Simple function that i found handy when dealing w/ ExecuteFunc, simply give it a main string and every time that second string appears it will be deleted from the returned string

Source

function RemoveSpaces takes string mainstring, string remover returns string
local string returner = ""
local integer i=0
local integer x = StringLength(remover)
local integer end = StringLength(mainstring)
 loop
   exitwhen i+x>end
    if SubString(x,i,i+x) != remover then
       set returner = returner +  SubString(mainstring,i,i+x)
       set i = i+(x-1)
    endif
    set i = i + 1
   endloop
return returner
endfunction

Comments

3
I think it's bugged...

Shouldn't it be more like this?:

 local integer x = StringLength(remover) - 1
...
 loop
  exitwhen i>end
  if SubString(mainstring,i,i+x) != remover then
   set returner = returner + SubString(mainstring,i,i)
   set i = i+1
  else
   set i = i + x
  endif
 endloop


Otherwise you might be skipping over instances of 'remover', ne?

However, I am just a clueless newbie.. I don't even know what the difference between SubString() (the one you used) and SubStringBJ(), the one you get when you convert the substring function in WE to custom text... but that's what it seems it should be...

edit: forgot about Markiz's observation.. changed to fix it.
edit 2: just learned what BJ means.. but I dont think it affects the code... ? o.0
edit 3 >.> maybe SubString works differently from SubStringBJ in that it's noninclusive or sth...? but it still looks like it only tests by sections.
umm i don't see it....
What does THAT mean?

local integer x = StringLength(remover)
//...
SubString([b]x[/b],i,i+x)

Error?