[英]Replacing a string from an built-in unknown character in python
I'm trying to replace this unrecognized text below here to a another text. 我正在尝试将此处无法识别的文本替换为另一文本。 What I did is decode it to UTF-8 and try to replace the unknown text below. 我所做的是将其解码为UTF-8,并尝试替换下面的未知文本。
" you " “你。”
varlistlabela = spss.GetVariableLabel(var)
varlistlabela=varlistlabela.decode("cp1252").replace(r'[\u0020-\ud7ff]',"").encode("cp1252")
You need a regex substitution: 您需要正则表达式替换:
re.sub(r'[^\u0020-\ud7ff]', '', s)
where s
is the input string. 其中s
是输入字符串。
Code : 代码 :
import re
s = " you�"
print(re.sub(r'[^\u0020-\ud7ff]', '', s))
# you
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.