- #!/usr/bin/python
- #-*- coding:utf-8 -*-
- # 因為程式碼本身是 utf-8, 所以先強制將字串轉碼成 BIG5
- strbig5 = "big 中文測試".decode('utf8','ignore').encode('big5','ignore')
- ii = 0
- while ii<(len(strbig5)-1):
- bCH = False
- s1 = strbig5[ii]
- s2 = ""
- if (ord(s1)>127):
- bCH = True
- s2 = strbig5[ii+1]
- print (s1+s2).decode('big5','ignore').encode('utf8','ignore') + " 的 ASCII : " + hex(ord(s1)).strip('0x') + hex(ord(s2)).strip('0x') + "\n"
- else:
- print s1 + " 的 ASCII : " + hex(ord(s1)) + "\n"
- if bCH:
- ii += 1
- ii += 1
沒有留言:
張貼留言