从文件中读出的一个汉字字符串
用这个句话判断是否包含回车:
python if '\n' in mystring:
print type(mystring)
#<type 'unicode'>
mystring.replace('\n', '')
#does not work
mystring.replace(u'\n', u'')
#does not work
mystring.encode("gbk")
mystring.replace("\n", "")
#does not work
mystring.encode("utf-8")
mystring.replace("\n", "")
#does not work
mystring.encode("ascii")
mystring.replace("\n", "")
#UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-20
print mystring
这该如何是好?请指教!
添加回答
举报
0/150
提交
取消