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: Seperate a string?

Previous Thread :: Next Thread 
FrozenSmite is not online. FrozenSmite
Joined: 17 Jul 2013
Total Posts: 2242
07 Oct 2013 03:00 PM
How do u seperate values in a string that has commas?
Like putting them into a table?
String = "1,2,3,4,5,6,7,8,9,10"
Into
StringTable = {"1","2","3","4","5","6","7","8","9","10"}

♫♪ repeat wait() until game.Players.FrozenSmite.HasALife == true ♪♫
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
07 Oct 2013 03:02 PM
s = "1,2,3,4,5,6,7,8,9,10"
StringTable = {}
for w in string.gmatch(s, ",") do
table.insert(StringTable,w)
end
Report Abuse
FrozenSmite is not online. FrozenSmite
Joined: 17 Jul 2013
Total Posts: 2242
07 Oct 2013 03:04 PM
That pulls out all the commas, but i understand now, ty.

♫♪ repeat wait() until game.Players.FrozenSmite.HasALife == true ♪♫
Report Abuse
ProjectsHidden is not online. ProjectsHidden
Joined: 29 Sep 2013
Total Posts: 194
07 Oct 2013 03:07 PM
function maketab(strin)
string = strin.."," --have to add one
local tab = {}
local ns = ""
for i = 1, string:len() do
if string:sub(i,i) == "," then
table.insert(tab, ns) ns = ""
else ns = ns..string:sub(i,i)
end
end
return tab end
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
07 Oct 2013 03:07 PM
woooops


s = "1,2,3,4,5,6,7,8,9,10"
StringTable = {}
for w in string.gmatch(s, "%w+") do
table.insert(StringTable,w)
end
Report Abuse
MutualSacrifice is not online. MutualSacrifice
Joined: 05 Oct 2013
Total Posts: 48
07 Oct 2013 03:14 PM
>>breuning
Wouldn't your first code be better for this situation? (In case of decimals and etc)
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
07 Oct 2013 03:33 PM
Here's a better version of breuning's code.

local string = "1,2,3,5,23,42,34,3" --random numbers seperated with commas
local tab = { }

for num in string:gmatch("[^,]+") do
table.insert(tab, num)
end

for _, v in pairs(tab) do
print(v)
end
Report Abuse
ProjectsHidden is not online. ProjectsHidden
Joined: 29 Sep 2013
Total Posts: 194
07 Oct 2013 03:43 PM
dig, use print(unpack(tab))) or print(table.concat(tab, " "))
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
07 Oct 2013 03:45 PM
ProjectsHidden: I know I could do that, but that wont work for every kind of table.

table.concat() and unpack() only work then the table uses numerical indexes (aka {'item1', 'item2' ...})
Report Abuse
ProjectsHidden is not online. ProjectsHidden
Joined: 29 Sep 2013
Total Posts: 194
07 Oct 2013 03:46 PM
In this case it is. Way to make you look smart.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
07 Oct 2013 03:48 PM
ProjectsHidden: True, but in most cases you're not using numerical indexes in tables and you can get a little used to not doing that.
Report Abuse
ProjectsHidden is not online. ProjectsHidden
Joined: 29 Sep 2013
Total Posts: 194
07 Oct 2013 03:51 PM
unpack works for anything.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
07 Oct 2013 03:53 PM
unpack does NOT work for anything.

I have proof it doesn't too.

Copied from the LuaForWindows Lua interpreter:

Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(unpack({Test="hi", "bye"}))
bye

See how it doesn't print 'hi'?

If I run the command print(({Test="hi", "bye"}).Test) it works fine though.

Obviously it doesn't work.
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