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

How can I take out a comma from a string and make it only as one number?

I can't figure out how to take out a comma from a string and make it only as one number.

print(string.match('Cost: $2,501', '(%d+)%z?,%z?(%d+)'))
-- Output: 2 501 -- It gives two numbers instead of just one.

2 answers

✓ Accepted answer

It's most likely something string.match does automatically when separating sets. You can simplify the string pattern you're using by using gmatch:

local str = ""

for i in ("Cost: $2,501"):gmatch("%d+") do
	str = str .. i
end

print(str)

1 comment

0

Thank you!

You could replace the comma using gsub and then match for any digits. Like so

print(string.match(string.gsub("Cost: $2,501", ",", ""), "%d+"))

1 comment

0

Thanks so much!

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