|
| 14 Nov 2013 10:54 AM |
I have a comma between two words, I want to turn each word into a variable e.g. the string is "blue,two" local colorvar = blue local numbervar = two
How would I turn the string into two variables? |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 11:09 AM |
function Split(String, At) for Letter =1, #String do if string.sub(String, Letter, Letter) == At then return string.sub(String, 1, Letter - 1), string.sub(String, Letter + 1) end end end
a, b = Split("lol,text", ",") print(a) print(b) |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 11:31 AM |
dude u a wiz kid
In all seriousness, thanks. I appreciate your contribution to my project, it won't be forgotten. |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 11:40 AM |
It could probably be made a lot better with gmatch or something But Im on a iPhone so yah I did my best, I don't understand gmatch much anyway |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 01:10 PM |
local col1, col2 = string.match("red,blue", "(%w+),(%w+)")
If you don't know how many colors will be listed, you'd want to use gmatch. |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 01:12 PM |
And you can use this for things other than colors. For example:
local n1, col, wrd = string.match("1231,purple,HELLO", "(%d+),(%w+),(%w+)) --> n1 = 1231, col = purple, wrd = HELLO |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 01:13 PM |
Feel like I'm spamming. Forgot to close that second string.
local n1, col, wrd = string.match("1231,purple,HELLO", "(%d+),(%w+),(%w+)") --> n1 = 1231, col = purple, wrd = HELLO |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 01:15 PM |
| Can you help me understand how all that seemingly random %+w and such works |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 02:41 PM |
| They're just string patterns. The wiki should be simple enough to explain it. :) |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 02:46 PM |
| I can't find it on the wiki |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 05:13 PM |
http://wiki.roblox.com/index.php/String_patterns
All you had to do was type in 'string patterns' in the search bar ... >_< |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 05:51 PM |
| this may be off topic, but cool your one of the top 100 posters. Now what's that mean? |
|
|
| Report Abuse |
|
|
|
| 14 Nov 2013 06:30 PM |
| Well when I search "string patterns" I get a ton of stuff that uses string patterns, and nothing explaining what it does |
|
|
| Report Abuse |
|
|