Warcraft III resources & community, 2003–2006 · archived

StringTrim

not rated
Submitted by PepparText Parsing0 downloads
Removes all spaces in the beginning and the end of string s.

The result is identical to StringTrimLeft( StringTrimRight( s ))

Source

function StringTrim takes string s returns string
    local integer l = -1
    local integer r = -1
    local integer i = 0
    local string c
    if s == "" or s == null then
        return s
    endif
    loop
        set c = SubString( s, i, i + 1 )
        exitwhen c == ""
        if c != " " then
            if l < 0 then
                set l = i
            endif
            set r = i + 1
        endif
        set i = i + 1
    endloop
    if l < 0 then
        return ""
    endif
    return SubString( s, l, r )
endfunction

Comments

0

No comments.