Warcraft III resources & community, 2003–2006 · archived

StringFind

not rated
Submitted by KaTTaNaText Parsing0 downloads
Returns the the position where the first occourence of 'find' appears in 'subject' starting the search from 'offset'. Returns -1 if 'find' wasn't found. This function is case-sensitive, for a case-insensitive version see: StringIFind.
Example:
StringFind("ass", "The Jass Vault", 1) == 6
StringFind("a", "The Jass Vault", 8) == 11

Source

// Returns -1 if find was not found anywhere
function StringFind takes string find, string subject, integer offset returns integer
    local integer len = StringLength(find)
    local integer pos = offset
    local string s
    local string str
    
    if ( offset < 1 ) then
        set pos = 1
    endif    
    if ( find == "" ) then
        return -1
    endif
    
    loop
        set s = SubStringBJ(subject, pos, pos+len-1)
        if ( s == find ) then
            return pos
        endif
        if ( SubStringBJ(subject, pos, pos) == "" ) then
            return -1
        endif
        set pos = pos + 1
    endloop
    return -1
endfunction

Comments

0

No comments.