Warcraft III resources & community, 2003–2006 · archived

String2IntGeneric

not rated
Submitted by KaTTaNaText Parsing0 downloads
This creates a generic integer basen on the given string.
This only works with strings containing no other characters than those present in the charMap local.
Note that some strings can generate the same result.

Source

function String2IntGeneric takes string s returns integer
    local string charMap = " !.#$%&'()*+,-./0123456789:;<=>.@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~"
    local integer i = 0
    local integer o = 0
    local integer result = 0
    local string char = ""
    local string match = ""
    loop
        set char = SubString(charMap, i, i+1)
        exitwhen (char == "") or (char == null)
        
        set o = 0
        loop
            set match = SubString(s, o, o+1)
            exitwhen (match == "") or (match == null)
            if ( match == char ) then
                set result = result + i*(o+1)
            endif
            set o = o + 1
        endloop
        
        set i = i + 1
    endloop
    return result
endfunction

Comments

0

No comments.