Lua:在字符串中查找十六进制值

我正在尝试在 Lua 中查找字符串中的十六进制不可打印字符 00h。我尝试使用转义字符,结果得到的位置与起始位置相同(这是可打印字符)。我试着挠了一下字符类,但没什么效果。我的方法看起来像这样:

location = string.find(variable,"\00",startlocation)

我还尝试了这种方式,但没有成功:

location = string.find(variable, string.char(00),startlocation)

如何在 Lua 中找到这个不可打印的模式?

原文链接 https://stackoverflow.com/questions/9032170

点赞
stackoverflow用户107090
stackoverflow用户107090

这对我很有效:

> 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
2012-01-27 10:56:28