[JASS] Is there a SubString like function just for Integers?

Status
Not open for further replies.
Level 18
Joined
Apr 13, 2008
Messages
1,629
Is there a SubString-like function just for Integers?

Hi, I was looking for a method to get the xth digit of an integer but I couldn't find a solution.
Is there a way to do this with an already implemented function or something?

I created a tiny function for myself, but I don't want to litter my map with unnecessary stuff.

JASS:
function SubInt takes integer source, integer start, integer end returns integer
return S2I(SubString(I2S(source), start, end))
endfunction
 
Converting to a substring then back again is a pretty inefficient way of doing it.

JASS:
function SubInt takes integer i, integer j, integer k returns integer
    set k = R2I(Pow(10, k-j))
    set i = i/R2I(Pow(10, j))
    return (i-(i/k)*k)
endfunction

JASS:
call BJDebugMsg(I2S(SubInt(123456789, 1, 5))) // displays "5678"
 
Status
Not open for further replies.
Back
Top