N
N
nonvon2022-02-28 20:19:39
Lua
nonvon, 2022-02-28 20:19:39

How to remove non-printable characters from a string?

I add this to the end of the line

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


but i can't remove it :(

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


Of course, I would like to remove

p / s from the end of the line; this is necessary so that the line is always a multiple of a certain number

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2022-03-01
@dollar

Just remove all "null" characters:

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

Remove only at the end of the line:
function zero_padding_remove(data)
  return string.gsub(data, '\0+$', '')
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question