Scite Hexify

lua-users home
wiki

轉換選取至轉譯的十六進位形式

有時你會想要找出文字的位元組值。

此腳本將選取內容轉換至 C 中使用的轉譯十六進位形式。使用復原 (Undo) 來移除轉換後的文字。

例如「abc」->「\x61\x62\x63」、「���T�」使用拉丁語系-1 編碼 ->「\x8a\xe7\xef\x54\xca」、「���T�」使用 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

最近更新 · 喜好設定
編輯· 歷史記錄
上次編輯日期為 2006 年 8 月 31 日 下午 7:47 GMT (差異)