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

How can I separate stringValues?

Asked by 6 years ago

Hello,

I am wondering how I can separate stringValues?

If I have a stringValue that has: "100 | Title | Views" All separated with a | is there a way I can make an array separating each of the bits of text between the "|"?

And also, how do I access different parts of an array?

Thanks, Ethan!

1 answer

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

try looking at these pages

https://www.lua.org/pil/20.2.html

http://lua-users.org/wiki/PatternsTutorial

http://wiki.roblox.com/index.php/String_pattern

code:

local raw = "100 | Title | Views"
local data = {}

for word in string.gmatch(raw, '([^ | ]+)') do -- looks for a pattern in the string
    table.insert(data, word) --add the separated version to data
end

--we can see if this worked by unpacking it
print(unpack(data)) 

output: 100 Title Views

0
Thank you! Starhawke_r 11 — 6y
Ad

Answer this question