• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

String to Integer question

Status
Not open for further replies.
Level 17
Joined
Nov 13, 2006
Messages
1,814
i want make a function what colorize the text depend its contain number/lower or uppercase letters

lets say udg_String = *random 100 character*

and i want check with loop each character, lower/uppercase character i think ok with if s==StringCase(s,true) then do action but i got problem with numbers coz S2I give 0 to every non number letter, but i got no clue how to make difference between this:

S2I("k") and S2I("0") coz result is same 0 in both case :/
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Isnt there a snippet for that?

e/
JASS:
library ColorCodeString
    function ColorCodeString takes string s, string numColor, string lowerColor, string upperColor, string specColor, integer start returns string
        local string ns = ""
        local string c
        local integer m = StringLength(s)
        local integer i = start
        local boolean l
        loop
            exitwhen m == i
            
            set c = SubString(s,i,i+1)
            
            if (c!=" ") then
                set l=StringCase(c,false)==c
                
                //special or number
                if (c==StringCase(c,true) and l) then
                    //number
                    if ("0"==c or 0!=S2I(c)) then
                        set ns=ns+"|cff"+numColor+c
                    //special
                    else
                        set ns=ns+"|cff"+specColor+c
                    endif
                //lowercase
                elseif (l) then
                    set ns=ns+"|cff"+lowerColor+c
                //uppercase
                else
                    set ns=ns+"|cff"+upperColor+c
                endif
            else
                set ns=ns+" "
            endif
            
            set i = i + 1
        endloop
        return ns
    endfunction
endlibrary
 
JASS:
function IsCharNumber takes string s returns boolean
    return I2S(S2I(s)) == s
endfunction

function IsCharLetter takes string s returns boolean
    return StringCase(s,true) != StringCase(s,false)
endfunction

function IsCharSymbol takes string s returns boolean
    return not IsCharLetter(s) and not IsCharNumber(s)
endfunction
 
Status
Not open for further replies.
Top