Jump to content




How do I split strings up?


  • You cannot reply to this topic
3 replies to this topic

#1 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 19 August 2012 - 09:02 AM

How would I split up a string? For instance I want to have a program that checks which words are types for instance: lights on.
Or something pretty basic like that, I know the obvious answer is to make a lights program then use args to turn on/off but I basically want to have a program to control the whole system (add users, del users, perms) and stuff like that.

#2 BigSHinyToys

  • Members
  • 1,001 posts

Posted 19 August 2012 - 09:14 AM

no read() cant split up a string
string.match() can
string.gmath() can
string.sub() can

But it depends on what you are trying to do
http://www.lua.org/m...#pdf-string.sub

#3 Pharap

  • Members
  • 816 posts
  • LocationEngland

Posted 19 August 2012 - 11:09 AM

 Human, on 19 August 2012 - 09:02 AM, said:

How would I split up a string? For instance I want to have a program that checks which words are types for instance: lights on.
Or something pretty basic like that, I know the obvious answer is to make a lights program then use args to turn on/off but I basically want to have a program to control the whole system (add users, del users, perms) and stuff like that.

I'd recommend doing something like:
local input = read()
if string.sub(input,1,3) = "Del" then
if string.sub(input,5,9) = "User" then
local user = string.sub(input,10)
DeleteUser(user)
end
end
end
And basically follow that pattern for all commands, not forgetting to account for the spaces between words.
You could also do it by breaking up the words with commas when writing and then in the code creating separate strings for the words between the commas.

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 August 2012 - 03:20 PM

Take a look at how the shell splits up command arguments to send to the programs it's running. That's how you'll want to do this.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users