如果字符串中包含 python 中的 \u,则删除字符串中的单词?
Remove words in string if it contains \u in python?
如果字符串中包含 \u in python?
,我想删除字符串中的单词
例如:
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?
如果字符串中包含 \u in python?
,我想删除字符串中的单词例如:
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?