checks if string only contains numbers

Hellohihi

New Member
Reaction score
42
How do i check if a string only contain numbers.
No letters allow, only whole numbers.

Is there a function for it?
 

Romek

Super Moderator
Reaction score
964
JASS:
function IsStringNumber takes string s returns boolean
   return I2S(S2I(s)) == s
endfunction
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
JASS:
function IsStringNumber takes string s returns boolean
   return I2S(S2I(s)) == s
endfunction

Romek's works great for any string that is less than or equal to 8 characters long.

Jass can only handle numbers up to 8 digits. However, for anything longer, you'd have to loop through the string 8 digits at a time.

JASS:
function isNumeric takes string str returns boolean
//returns whether a string only contains numbers
    local integer i = 0
    local string s
    loop
        set s = SubString(str, i, i + 8)
        exitwhen s == null
        if I2S(S2I(s)) != s then
            return false
        endif
        set i = i + 8
    endloop
    return true
endfunction


Can be found in my Advanced Strings System. If you're working a lot with strings, you may find something useful in it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top