Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using string.find or string.match, how could I get these numbers?

Asked by 6 years ago

I want to use string.find to get any string that is any 4 digits, then a space, and another 4 digits (example: "6969 6969"). I've tried "%d%d%d%d %d%d%d%d" and "%d%d%d%d%s%d%d%d%d" and also "%d%d%d%d".." ".."%d%d%d%d" and nothings worked. Someone please help, thanks.

0
use the string.sub function, example: if string.sub("6969 6969", 1, 5) == " 6969 " then --... end User#19524 175 — 6y
0
@incapaz, that's not precisely what he is asking for. laughablehaha 494 — 6y
0
an example for that specific string. User#19524 175 — 6y
0
No, the string must return true if it matches with ANY 4 digits, a space, and then ANY 4 digits. "6969 6969" was the example. puhpuh48 4 — 6y
0
String.find looks for the first match of patterns in string s. If a match is found, then String.find returns the locations (1, 3, etc.) ABK2017 406 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Try using string.match.

string.match will search through a string for a pattern (second argument), and return the first matching substring if one is found

http://robloxdev.com/articles/string-patterns-reference

Pattern you want:

"%d%d%d%d%s%d%d%d%d"

Example of how this works:

local pattern = "%d%d%d%d%s%d%d%d%d"
local string = "7394 1027"

local match = string.match(string,pattern)
print(match)

Output: 7394 1027

Your pattern was missing the whitespace character class, %s.

0
Thanks! puhpuh48 4 — 6y
Ad

Answer this question