是否有字符串函数来修剪astring中的所有非ascii字符 [英] Is there a string function to trim all non-ascii characters out of astring
问题描述
是否有一个字符串函数来修剪
字符串中的所有非ascii字符?
假设我在python中有一个字符串(这是utf8编码的),是否有一个
python函数,我可以将其转换为一个字符串,其中包含
只有ascii字符?
谢谢。
Hi,
Is there a string function to trim all non-ascii characters out of a
string?
Let say I have a string in python (which is utf8 encoded), is there a
python function which I can convert that to a string which composed of
only ascii characters?
Thank you.
推荐答案
12月31日凌晨2:20,silverburgh。我... @ gmail.com"
< silverburgh.me ... @ gmail.comwrote:
On Dec 31, 2:20 am, "silverburgh.me...@gmail.com"
<silverburgh.me...@gmail.comwrote:
是否有字符串函数用于修剪
字符串中的所有非ascii字符?
假设我有一个字符串python(这是utf8编码),是否有一个
python函数,我可以将其转换为一个字符串,其中只包含ascii字符
?
谢谢。
Hi,
Is there a string function to trim all non-ascii characters out of a
string?
Let say I have a string in python (which is utf8 encoded), is there a
python function which I can convert that to a string which composed of
only ascii characters?
Thank you.
def ascii_chars(string):
返回''''。join(如果是ord(char),则为字符串中的char的char< 128)
def ascii_chars(string):
return ''''.join(char for char in string if ord(char) < 128)
12月31日,1:20 * pm,silverburgh.me ... @ gmail.com
< silverburgh.me ... @ gmail.comwrote:
On Dec 31, 1:20*pm, "silverburgh.me...@gmail.com"
<silverburgh.me...@gmail.comwrote:
是否有字符串函数来修剪所有非 -
字符串中的-ascii字符?
假设我在python中有一个字符串(这是utf8编码的),是否有一个
python函数,我可以将其转换为一个字符串组成的
只有ascii字符?
谢谢。
Hi,
Is there a string function to trim all non-ascii characters out of a
string?
Let say I have a string in python (which is utf8 encoded), is there a
python function which I can convert that to a string which composed of
only ascii characters?
Thank you.
使用此功能 -
def omitNonAscii(nstr):
sstr =' '''
对于ns中的r
:
如果ord(r)< 127:
sstr + = r
返回sstr
Use this function --
def omitNonAscii(nstr):
sstr=''''
for r in nstr:
if ord(r)<127:
sstr+=r
return sstr
12月31日下午7:20,silverburgh.me ... @ gmail.com
< ; silverburgh.me ... @ gmail.comwrote:
On Dec 31, 7:20 pm, "silverburgh.me...@gmail.com"
<silverburgh.me...@gmail.comwrote:
是否有一个字符串函数来修剪所有
字符串中的非ascii字符?
假设我在python中有一个字符串(这是utf8编码的),是否有一个
python函数,我可以将其转换为仅由ascii字符组成的字符串?
Hi,
Is there a string function to trim all non-ascii characters out of a
string?
Let say I have a string in python (which is utf8 encoded), is there a
python function which I can convert that to a string which composed of
only ascii characters?
这篇关于是否有字符串函数来修剪astring中的所有非ascii字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!