Lua strings 'n' things
New to Lua, need to check if a string exists inside another string, and can't seem to figure it out, how do I?
In PHP this'd be:
<?php
$pos = strpos($haysta开发者_运维技巧ck,$needle);
if($pos === false) {
// string needle NOT found in haystack
} else {
// string needle found in haystack
}
?>
Also need to chop off the last char of a string...
http://lua-users.org/wiki/StringLibraryTutorial
print(string.find("foobar", "foo"))
yields...
1 3
print(string.find("foobar", "baz"))
yields...
nil
print(string.sub("foobar", 1, 5))
yields...
fooba
For chopping the last character, you can use a negative index:
string.sub("the string.", 1, -2)
精彩评论