Jump to content




Splitting Strings


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

#1 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 30 January 2013 - 08:04 AM

Hello,

I know there are many posts about this, but I don't understand a single word, so I hope someone can explain me some stuff.

I want a program to check if in the startup file exists a line with "shell.run". (Anything can be behind it)

How is that possible?

#2 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 30 January 2013 - 08:12 AM

You would do something like this:

local f = io.open("/startup", "r") -- open the startup file for reading
local data = f:read("*a") -- read the entire file
f:close() -- close the file

if data:find("shell.run") then -- check if "shell.run" exists in the file contents.
    print("Found a line with shell.run!")
end


#3 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 30 January 2013 - 08:17 AM

Thanks ~_~

#4 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 30 January 2013 - 08:17 AM

Btw, it has nothing to do with splitting strings :)

#5 svdragster

  • Members
  • 222 posts
  • LocationGermany

Posted 30 January 2013 - 08:19 AM

xD Fail, well that's the only thing I found while searching for something like this...

#6 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 30 January 2013 - 08:20 AM

IIRC, :find() uses pattern matching, so you should probably escape that dot when looking for shell.run.

if data:find("shell%.run") then


#7 Mads

  • Members
  • 604 posts
  • LocationCopenhagen, Denmark

Posted 30 January 2013 - 08:27 AM

Would be
if data:find("shell\.run") then


#8 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 30 January 2013 - 08:37 AM

View Postmad, on 30 January 2013 - 08:27 AM, said:

Would be
if data:find("shell\.run") then
No, patterns in lua are escaped with a %. It's not the same as escaping strings. It's just indicating that the character (dot) is not a magic symbol, but just a plain dot.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users