✓ Accepted answer
I wouldn't exactly call my answer simple, but I'll try to explain as best as I can. I'll show you how this can be accomplished with string.match() and string patterns.
local testString = "/walkspeed 52"
local command,number = string.match(testString,"^/(%a+) (%d+)")
print(command)
print(number)
string.match is used to find where in a string that a pattern may exist. In the example our pattern is ^/(%a+) (%d+). First there is the ^, this makes it so it will only check if the pattern exists at the beginning of the string. Next is the / which is our first character to match. After that we have (), these in a string pattern are called captures, it tells string.match that it should return what it matches between them. And last we have %a+ and %d+. %a makes the pattern match a letter and %d makes the pattern match a digit. The + extends the pattern matching to search for one or more character, so %a+ will search for one or more letters.
2 comments
This is one of your better answers. Keep it up!
Thanks! I'm glad it helped.