Is there a string.sub-like command for int variables?
Let’s say I need to find the second character in the number 1328 (which is 3).
Is there a string.sub-like command for int variables?
Let’s say I need to find the second character in the number 1328 (which is 3).
not sure, but couldn’t you just use tostring()
and then tonumber()
?
local inputString = tostring(number)
local result = tonumber(string.sub(inputString, tostring(searchNumber)))
if result then
print(result)
end
Of course I can, but I asked about such a command because I wanted less writing in my code, and in this case there is even more of it than I have right now.
You do not have to convert int variable to string in order to use string.sub()
string.sub(), however, will return a string value. But it will not be a problem because whenever you try to perform any mathematical operations with it, Luau will automatically try to convert it into a number.
I do not know a way to make it shorter
print(tonumber(tostring(Value):sub(Pos,Pos)))
Then: local d = math.floor(n / 10^(#tostring(n) - 2)) % 10
why not just make new function then?
Thanks for your answers, but I just needed to know that such a command exists. Your solutions can’t help because I didn’t provide the context.
And by the way, this information is useful, so let me mark it as a solution.