HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 06:20 PM |
I have a string, for example: a = "asd/g4/awe5/s"
The amount of slashes vary. I want to run a script that automatically sees how many slashes exist, and adds into a table whats in between each slash, so that the table would look like this: tab={"asd","g4","awe5","s"}
|
|
|
| Report Abuse |
|
|
|
| 05 Jan 2012 06:23 PM |
Tab = { Slashes = 0 table.insert(Tab, a:match("(.-)/") for sor in a:gmatch("/(%w+)") do Slashes = Slashes + 1 table.insert(sor) end
print(unpack(Tab), Slashes) |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 05 Jan 2012 06:27 PM |
*table.insert(Tab, sor)
If I find one more mistake, I'm gonna BLOW UP |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 06:29 PM |
| u forgot paranthesis in the end of the string thing |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 06:36 PM |
issnot really working.. Tab = {} Slashes = 0 a = "asd/g4/awe5/s" --table.insert(Tab, a:gmatch("/(%w-)")) for sor in a:gmatch("/(%w-)") do Slashes = Slashes + 1 table.insert(Tab, sor) end
print(unpack(Tab), Slashes) |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2012 07:16 PM |
Tab = {} Slashes = 0 a = "asd/g4/awe5/s" table.insert(Tab, a:match("(%w-)/")) for sor in a:gmatch("/(%a+)") do Slashes = Slashes + 1 table.insert(Tab, sor) end |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:18 PM |
Thanks. Almost though, it doesn't count the numbers :I |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 05 Jan 2012 07:23 PM |
table.foreach(Tab, print)
<---dun lik string patterns |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 05 Jan 2012 07:23 PM |
table.foreach(Tab, print)
<---dun lik string patterns |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
| |
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:24 PM |
| yea, but that doesn't help me :/ |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:25 PM |
Tab = {} Slashes = 0 a = "HatHelper/Snow Zombie" table.insert(Tab, a:match("(%w-)/")) for sor in a:gmatch("/(%w+)") do table.insert(Tab, sor) end print(table.concat(Tab, ' '))
This works to a certain extent. It doesn't recognize the space character. I tried replacing with other non-letter characters, but "%w" only works for alphabet and numbers.
|
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 05 Jan 2012 07:26 PM |
| you wanted it to count them out? |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:27 PM |
No? Read the thread. Or just the first post. |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2012 07:43 PM |
AMG!
txt = "" t = {} for M in txt:match("(%w+)/?") do table.insert(t, M) end
table.foreach(t, print) |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:45 PM |
| " attempt to call a string value" |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2012 07:49 PM |
Onoes. table.foreach doesn't work anymore. I also forgot the g in gmatch. >_>
txt = "asdf/321d/123rwdcff/12rwsed/gdsfhdsa/3rtge/r" t = {} for M in txt:gmatch("(%w+)/?") do table.insert(t, M) end
for _, v in pairs(t) do print(v) end |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:50 PM |
problem :0
txt = "HatHelper/Snow Zombie" t = {} for M in txt:gmatch("(%w+)/?") do table.insert(t, M) end
for _, v in pairs(t) do print(v) end
Prints Snow Zombie as two words.
|
|
|
| Report Abuse |
|
|
|
| 05 Jan 2012 07:54 PM |
| After a few experiments, I will post the approximate source of the string.gmatch function. ;P |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2012 07:54 PM |
txt = "HatHelper/Snow Zombie" t = {} for M in txt:gmatch("([%w+%s*]+)/?") do table.insert(t, M) end
for _, v in pairs(t) do print(v) end |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:54 PM |
| I'm tempted to just use loops to figure it out |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2012 07:55 PM |
String patterns. Are fun. Don't give up! I'm currently working on a differentiation function to differentiate my equations for me. For Calculus. :o :o :o :o |
|
|
| Report Abuse |
|
|
HatHelper
|
  |
 |
| Joined: 02 Mar 2009 |
| Total Posts: 46305 |
|
|
| 05 Jan 2012 07:56 PM |
i aint to calculus so idk
i dont understand string patterns at all yet. ill teach myself tomorrow at school.
|
|
|
| Report Abuse |
|
|