Scite Hexify

lua-users home
wiki

Convert selection to hex escaped form

Sometimes you would like to find out the byte values of text.

This script converts the selection to escaped hex form as used in C. Use Undo to remove the converted form.

For example "abc" -> "\x61\x62\x63", "T" in Latin-1 -> "\x8a\xe7\xef\x54\xca", "T" in UTF-8 -> "\xc5\xa0\xc3\xa7\xc3\xaf\x54\xc3\x8a".

-- Convert a string to a string of hex escapes
function Hexify(s) 
  local hexits = ""
  for i = 1, string.len(s) do
    hexits = hexits .. string.format("\\x%2x", string.byte(s, i))
  end
  return hexits
end

-- Convert the selection to hex escaped form
-- command.name.1.*=Hexify Selection
-- command.mode.1.*=subsystem:lua,savebefore:no
-- command.1.*=HexifySelection
function HexifySelection()
  editor:ReplaceSel(Hexify(editor:GetSelText()))
end

RecentChanges · preferences
edit · history
Last edited August 31, 2006 6:47 pm GMT (diff)