Warcraft III resources & community, 2003–2006 · archived

StringReplace

not rated
Submitted by KaTTaNaText Parsing0 downloads
Returns a string where all occournces of 'find' in 'subject' are replaced by 'replace'.
*Requires: StringFind
Example:
StringReplace("s", "ABC", "The Jass Vault is a community") == "The JaABCABC Vault iABC a community"
StringReplace("Rules", "Owns", "KaTTaNa Rules") == "KaTTaNa Owns"

This function is case-sensitive because StringFind is.

Source

function StringReplace takes string find, string replace, string subject returns string
    local integer pos = 1
    local integer i
    local string result = ""
    local integer len = StringLength(find)
    
    loop
        set i = StringFind(find, subject, pos)
        if ( i > -1 ) then
            if ( i > pos ) then
                set result = result + SubStringBJ(subject, pos, i-1) + replace
            else
                set result = result + replace
            endif
            set pos = i + len
        else
            set result = result + SubStringBJ(subject, pos, 999999)
            return result
        endif
    endloop
    return subject
endfunction

Comments

0

No comments.