Lua delete invisible padding (SOLVED)

This add ‘\0’ zerro padding

function zero_padding_add(data, blocksize)
	local pad = blocksize - math.fmod(#data, blocksize)
	return data .. string.rep('\0', pad)
end

and how i remove it ? this don`t work

function zero_padding_remove(data)
	return string.gsub(data, "\0", '')
end

analog in php

rtrim($data, "\0");

\ is an escape character. Instead of “\0” in your gsub, try “\\0”.

Edit: turns out it’s an escape character in the forum too, had to do three \ to display two of them!

1 Like
string.gsub(data, '%z', '')

:sweat_smile:
%z Zero character (0)

How i make made mark this topic is complete?

The question turned out to be simple - but not googled (((

You can edit the title of your original post and put (SOLVED) at the end.

1 Like

Happy to hear that you figured it out! It’s documented in the official Lua manual in the patterns chapter:

https://www.lua.org/pil/20.2.html

%z the character with representation 0

1 Like

:+1: