只是想知道如何將一個Unicode字符串如u'é'
轉換爲其Unicode字符代碼u'\xe9'
?如何使用Python將unicode字符串中的重音字符轉換爲unicode字符代碼?
2
A
回答
2
您可以使用Python repr()功能:
>>> unicode_char = u'é'
>>> repr(unicode_char)
"u'\\xe9'"
1
ord
會給你的數值,但你必須將其轉換爲十六進制:
>>> ord(u'é')
233
1
u'é」和u '\ xe9'完全一樣,它們只是不同的表示:
>>> u'é' == u'\xe9'
True
相關問題
- 1. 將url編碼的字符串轉換爲python unicode字符串
- 2. Unicode字符串爲Unicode字符,Python 3
- 3. 如何將字符串轉換爲Perl中的unicode字符串
- 4. 如何將Unicode轉義序列轉換爲.NET字符串中的Unicode字符?
- 5. 如何將逐字字符串轉換爲常規Unicode字符
- 6. 在Unicode中將unicode字符串轉換爲可用的unicode
- 7. 如何將Shift_JIS字符代碼轉換爲python中的unicode字符?
- 8. java字符串unicode代碼點轉換爲字符
- 9. 如何將帶有Unicode字符的字符串轉換爲普通字符串?
- 10. 如何將unicode字符串轉換爲字符
- 11. 使用unicode字轉換字符串
- 12. python中unicode字符串的轉換
- 13. 如何將unicode字符串轉換像
- 14. 轉換八位字節字符串轉換爲Unicode字符串,Python 3中
- 15. 將RTF字符串中的unicode字符轉換爲純文本
- 16. 將AnsiString轉換爲Unicode字符串
- 17. 將unicode字符串轉換爲float
- 18. 將unicode字符串轉換爲utf8
- 19. 將Unicode字符串轉換爲ASCII
- 20. 將字符串中的特殊字符轉換爲Unicode十六進制代碼?
- 21. 在python中轉換unicode字符串
- 22. 轉換到Unicode字符串
- 23. 如何將unicode字符轉換爲java中的實際字符?
- 24. 如何將unicode數組轉換爲Python中的字符串
- 25. 位移並將字符轉換爲Unicode轉義字符串
- 26. 字符串轉換爲使用非英文字符(Unicode)的
- 27. 如何將Unicode字符串轉換爲java中的ASCII碼
- 28. 如何將unicode字符轉換爲delphi 7中的ascii代碼?
- 29. 如何將印度語字符轉換爲Unicode轉義字符
- 30. 如何將寬字符串轉換爲unicode字節的字符串?
表達式在python中評估爲True,而在ipython中評估爲False。爲什麼會發生這種情況?謝謝! – boativan66 2010-08-17 20:21:38
@ boativan66:在複製粘貼過程中,您可能已將其轉換爲「u'e \ u0301」。嘗試'unicodedata.normalize('NFC',u'é')== u'\ xe9'' – jfs 2015-10-14 06:14:13