V.A*_*Anh 13 python unicode python-2.7
我在Python中有一个字符串,如下所示:
u'\u200cHealth & Fitness'
Run Code Online (Sandbox Code Playgroud)
我怎么能删除
\u200c
Run Code Online (Sandbox Code Playgroud)
部分来自字符串?
Aro*_*unt 38
您可以将其编码ascii并忽略错误:
u'\u200cHealth & Fitness'.encode('ascii', 'ignore')
Run Code Online (Sandbox Code Playgroud)
输出:
'Health & Fitness'
Run Code Online (Sandbox Code Playgroud)
Hay*_*yat 18
如果你有一个包含Unicode字符的字符串,比如
s = "Airports Council International \u2013 North America"
Run Code Online (Sandbox Code Playgroud)
然后你可以尝试:
newString = (s.encode('ascii', 'ignore')).decode("utf-8")
Run Code Online (Sandbox Code Playgroud)
输出将是:
Airports Council International North America
Upvote如果有帮助 :)
小智 13
我只是使用替换因为我不需要它:
varstring.replace('\u200c', '')
Run Code Online (Sandbox Code Playgroud)
或者在你的情况下:
u'\u200cHealth & Fitness'.replace('\u200c', '')
Run Code Online (Sandbox Code Playgroud)
对我来说以下有效
mystring.encode('ascii', 'ignore').decode('unicode_escape')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28937 次 |
| 最近记录: |