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 » Scripters
Home Search
 

Re: Does Lua have a split function to break apart strings?

Previous Thread :: Next Thread 
Laakari is not online. Laakari
Joined: 07 Aug 2014
Total Posts: 17362
14 Apr 2016 09:54 PM
Like in Python:

string = "Hello,there!"

newArray = string.split(",")

print(newArray)

>>> '["Hello", "there!"]'


Report Abuse
DivinePheonix is not online. DivinePheonix
Joined: 30 Mar 2011
Total Posts: 11190
14 Apr 2016 09:55 PM
Not completely sure in all honesty, but you can always use string.find and string.sub to cut it.
Take a look for yourself:
http://wiki.roblox.com/index.php?title=Function_dump/String_manipulation
Report Abuse
Laakari is not online. Laakari
Joined: 07 Aug 2014
Total Posts: 17362
14 Apr 2016 09:59 PM
Nah I don't see it.

Dang, that would simplify a script I'm making using chatted events.

Oh well, I guess I will use that method.


Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
14 Apr 2016 10:11 PM
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end

tabbleOfSplitStringWithAComma = ("a,bb,ccc,ddd"):split(",")


Report Abuse
gskw is not online. gskw
Joined: 05 Jan 2013
Total Posts: 1364
14 Apr 2016 11:47 PM
^ You can't change the string table
Report Abuse
earthyreuben is not online. earthyreuben
Joined: 17 Jan 2010
Total Posts: 669
15 Apr 2016 01:17 AM
http://lua-users.org/wiki/SplitJoin

for i in string.gmatch(example, "%S") do
print(i)
end

or for words
for i in string.gmatch(example, "%S+") do
print(i)
end
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
15 Apr 2016 01:25 AM
local myString = "a,bb,ccc,ddd"

split = function(str, mark)
local tab = {}
for val in str:gmatch("[^%"..mark.."]+") do
tab[#tab + 1] = val
end
return tab
end

local myTab = split(myString,",")

for i,v in next, myTab do
print(v)
end


Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
15 Apr 2016 04:02 AM
thanks for the credit mong.
Report Abuse
Neon_JJ5x5 is not online. Neon_JJ5x5
Joined: 16 Oct 2014
Total Posts: 7
15 Apr 2016 04:19 AM
You can change the string value.


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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