Python: Convert Unicode-Hex-String to Unicode

后端 未结 3 1463
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 19:35

I have a hex-string made from a unicode string with that function:

def toHex(s):
    res = \"\"
    for c in s:
        res += \"%02X\" % ord(c) #at least 2          


        
3条回答
  •  甜味超标
    2021-01-05 19:52

    When I was working with Unicode in a VB app a while ago the first 1 or 2 digits would be removed if they were a "0". Meaning "&H00A2" would automatically be converted to "&HA2", I just created a small function to check the length of the string and if it was less than 4 chars add the missing 0's. I'm not sure if this is what's happening to you, but I thought I would give bit of information as something to be aware of.

提交回复
热议问题