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!
✓ ANSWER ACCEPTED
Is there a way to check if a string has a number in it and if so to return it?
1 answer
✓ Accepted answer
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
1 comment
0
Thank you so much
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
https://wiki.roblox.com/index.php?title=Global_namespace/String_manipulation#string.find
I don't think you understand. I don't know what the number will be before hand.
I didn't know what you meant by return, go to the script where the number is being generated in the first place and print it
I cannot do that. It is being generated by a user.