0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

IMEオフに出来ない環境で自動入力された16進文字列の変換

Posted at
def restore_hex(ime_text):
    replace_map = {
        "": "a", "": "e",
        "": "ba", "": "da", "ふぁ": "fa",
        "": "be", "": "de", "ふぇ": "fe"
    }
    
    zenkaku_to_hankaku = str.maketrans(
        "0123456789abcdefABCDEF",
        "0123456789abcdefABCDEF"
    )

    result = ""
    i = 0
    while i < len(ime_text):
        if i < len(ime_text) - 1 and ime_text[i:i+2] in replace_map:
            result += replace_map[ime_text[i:i+2]]
            i += 2
        elif ime_text[i] in replace_map:
            result += replace_map[ime_text[i]]
            i += 1
        else:
            result += ime_text[i].translate(zenkaku_to_hankaku)
            i += 1

    return result
s = restore_hex(s)
val = int(s, 16)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?