The title says it all. How can I check and see if there is an integer inside of a string and if there is to return that number? Thanks for any help!
You are able to use string patterns to isolate numbers from a string. The %d
character class represents any digit, and adding the +
represents that you want to retrieve any number of digits next to each other, so you can use string.match
with this info to retrieve numbers from the string:
local function GetNumbers(String) return string.match(String,"%d+") end print(GetNumbers("banana 63 banana")) --> 63