Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua: Find hex-value in string

I'm trying to find the hexadecimal non-printable character 00h within a string with Lua. I tried it with an escape character and as a result I get the same location I start in (that's a printable character). I fiddled around with the character classes, but that didn't amount to anything. My approach looks like this:

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

I also tried it this way, but no luck:

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

How can I find this non-printable pattern in Lua?

like image 962
Zerobinary99 Avatar asked Jun 04 '26 07:06

Zerobinary99


1 Answers

It works fine for me:

> 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
like image 152
lhf Avatar answered Jun 06 '26 03:06

lhf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!