Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to only get a number column?

For example, I want to grab the tens column out of a 4-digit number. 1|5|1|4 How could I do that?

1 answer

✓ Accepted answer

Well, I guess you can use string manipulation, and exactly string:sub(). Tens in your occasion are in the 3rd collumn. So

local number = tostring(1415)
print(number:sub(3,3))
-- and printing that would give 1, since that's ten

But that wouldn't work everytime, what if the number was 147587 or something like that, tens wouldn't be third. So what we can do is, string:reverse() which will gurante the tens to be always second.

local number = tostring(1415)
number:reverse():sub(2,2)
-- this would always work

Another problem, what if there are decimal places? Welp, easy, use string:find() to find that comma "," and sub the string from there.

local number = tostring(1415,75) 
print(number:reverse():sub(number:find(",")+1,#number):sub(2,2))

-- and this should work, we inversed our string, sub'd starting from the comma + 1 (we did +1 since :find will return the index of the given character inside a string, and subbing "includes" the minimum and maximum which were set, which means the comma will exist in our string and we wouldnt want that, that's why we added 1 to the index, so we can include the character after the comma) and #number or pretty much #any string would return the amount of character a string would have, so we our given string will stop at the final character.

And yeah, that's pretty much it, I tested this, and it worked with any combination I put, so yeah, it's rally cool what you can manipilate with strings.

local number = "1475,75"
local string = number:reverse()
local stringity = string:sub(string:find(",")+1,#number):sub(2,2)
print(stringity)

3 comments

0

tbt

0

Thank you

0

no problem

This discussion is preserved as it was. New answers, comments, and votes are closed.