2024-03-29 13:01:00 发布
网友
如果字符串中包含python中的\u,我想删除其中的单词?你知道吗
例如:
string ="\uf064thickness cfoutside\uf0d7\uf03a\uf03d TC2019 45TRCMat"
最终输出应该是这样的。你知道吗
"TC2019 45TRCMat"
删除所有包含\u的单词后
如果不想删除unicode字符,请改为只允许使用ascii字符:
string ="\uf064thickness cfoutside\uf0d7\uf03a\uf03d TC2019 45TRCMat" def is_ascii(s): return all(ord(c) < 128 for c in s) for s in string.split(" "): if is_ascii(s): print(s)
引用:How to check if a string in Python is in ASCII?
如果不想删除unicode字符,请改为只允许使用ascii字符:
引用:How to check if a string in Python is in ASCII?
相关问题 更多 >
编程相关推荐