Warcraft III resources & community, 2003–2006 · archived

StringIFind

not rated
Submitted by KaTTaNaText Parsing0 downloads
Case in-sensitive find. Returns the beginning of the first occourence of 'find' in 'subject', starting the search at 'offset'.
For a case-sensitive version, see StringFind.

Examples:
StringIFind("Ass", "The Jass Vault", 1) == 6
StringIFind("A", "The Jass Vault", 8) == 11

Source

// Returns -1 if find was not found anywhere
function StringIFind takes string find, string subject, integer offset returns integer
    local integer len = StringLength(find)
    local integer pos = offset
    local string s
    local string str
    set find = StringCase(find, false)
    
    if ( offset < 1 ) then
        set pos = 1
    endif    
    if ( find == "" ) then
        return -1
    endif
    
    loop
        set s = SubStringBJ(subject, pos, pos+len-1)
        if ( StringCase(s, false) == 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.