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)
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论