Ex for desired result I:
“abcd123efgh525” ->123
Ex for desired result II:
“abcd123efgh525” -> {123,525}
I am invalid with strings. How do you recommend approaching this?
Ex for desired result I:
“abcd123efgh525” ->123
Ex for desired result II:
“abcd123efgh525” -> {123,525}
I am invalid with strings. How do you recommend approaching this?
For the first one you would do
("abcd123efgh525"):match("%d+")
since it returns 1 or more occurrences of digits “in a row”. So at the character "e"
it would stop.
For the second one you can do
local digits = { }
for occurrence in ("abcd123efgh525"):gmatch("%d+") do
table.insert(digits, tonumber(occurrence))
end
Since you go through all occurrences of digits in a row.
This does not support decimal numbers. I found out you can do that with:
local numberValue = tonumber("string1.25string":match("[%.%d]+"))
--returns 1.25