[英]How to add a backlash (\) at the beginning and the end of a string in Python
[英]How to decode double backlash string in python?
輸入字符串是 string = '\\\四\\\川\\\黃\\\龍\\\復\\\華\\\度\\\假\\\世\\\界'
。 注意是雙斜線,不是單斜線。
如何用gbk
編碼解碼得到四川黃龍復華度假世界
?
在這里,簡單的替換方法不起作用。 最簡單的方法是執行以下操作:
from codecs import unicode_escape_decode
text = '\\u56db\\u5ddd\\u9ec4\\u9f99\\u590d\\u534e\\u5ea6\\u5047\\u4e16\\u754c'
decoded_text = unicode_escape_decode(text)
print(decoded_text)
輸出:四川黃龍復華度假世界
以下代碼片段適用於Python 3.8.6 … on win32 :
texte = '\\u56db\\u5ddd\\u9ec4\\u9f99\\u590d\\u534e\\u5ea6\\u5047\\u4e16\\u754c'
textd = repr(texte).replace('\\\\','\\').strip("'").encode().decode("unicode-escape")
print(textd)
四川黃龍復華度假世界
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.