Warcraft III resources & community, 2003–2006 · archived

IndexOfSubstring()

not rated
Submitted by Die_BackeFunctions0 downloads
it is opensource, first created by mueslirocker.
It searches for the second parameter in the first one, and returns the index of the first instance of that substring. use SubStringBJ, or you will have to subtract 1 from the result.
an important function to me, i use it for every of my calculation stuff, that workes with a charmap.

Source

function IndexOfSubstring takes string text, string searchtext returns integer
    local integer i = 1
    if (StringLength(text) >= StringLength(searchtext)) then
        loop
            exitwhen (i > (StringLength(text) - StringLength(searchtext) + 1))
            if (SubStringBJ(text,i,i + StringLength(searchtext) - 1) == searchtext) then
                return i - 1
            endif
            set i = i + 1
        endloop
    endif
    return -1
endfunction

Comments

0

No comments.