我正在尝试使用 Lua 在字符串中查找十六进制不可打印字符 00h。我用转义字符尝试了它,结果我得到了我开始的相同位置(这是一个可打印的字符)。我摆弄了字符类,但这没有任何意义。我的方法是这样的:
location = string.find(variable,"\00",startlocation)
我也试过这种方法,但是没有运气:
location = string.find(variable, string.char(00),startlocation)
如何在 Lua 中找到这种不可打印的模式?
最佳答案
它对我来说很好用:
> return string.find("one\0two\0,three","\0,")
8 9
> return string.find("one\0two\0,three","\0")
4 4
> return string.find("one\0two\0,three","\00")
4 4
> return string.find("one\0two\0,three","\00",6)
8 8
关于Lua:在字符串中查找十六进制值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9032170/