Python strip()unicode字符串?

标签 python string unicode strip

如何在 unicode 字符串上使用像 strip() 这样的字符串方法?您不能像使用普通字符串那样访问 unicode 字符串的字符吗? (例如:mystring[0:4])

最佳答案

它像往常一样工作,只要它们实际上是 unicode,而不是 str(注意:每个字符串文字 必须 前面有 u,就像在这个例子中一样):

>>> a = u"coțofană"
>>> a
u'co\u021bofan\u0103'
>>> a[-1]
u'\u0103'
>>> a[2]
u'\u021b'
>>> a[3]
u'o'
>>> a.strip(u'ă')
u'co\u021bofan'

关于Python strip()unicode字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7258411/

相关文章:

python - 使用 Python C-API 的类属性

python - 如何将文本文件读入字符串变量并去除换行符?

delphi - 为什么TStringStream转换为字符串时不去掉BOM?

c - UEFI 编程 : How to Initialize a CHAR16 Unicode String?

python - 多个周期性定时器

python - 不区分大小写的数组查询 Flask-SQLAlchemy

python - 在 Python 中提取跨多行的引号之间的字符串

c - 如何将 char 传递给函数?

c++ - 输出句子中单词的第一个字母

Java URLDecoder 返回?