generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Splitting a string...

Previous Thread :: Next Thread 
UndeleteTool is not online. UndeleteTool
Joined: 15 Mar 2012
Total Posts: 1851
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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
UndeleteTool is not online. UndeleteTool
Joined: 15 Mar 2012
Total Posts: 1851
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
14 Nov 2013 01:15 PM
Can you help me understand how all that seemingly random %+w and such works
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
14 Nov 2013 02:41 PM
They're just string patterns. The wiki should be simple enough to explain it. :)
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
14 Nov 2013 02:46 PM
I can't find it on the wiki
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
greatgavin is not online. greatgavin
Joined: 20 Jul 2009
Total Posts: 389
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
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image