代码
str = str.replace(u'\u3000',u'').replace('\n', '').replace('\r', '').replace(" ","")
问题
-
在python中存在继承了 回车符
\r
和 换行符\n
两种标记,如果只是去除\n
,并不会起效果,需要replace('\n', '').replace('\r', '')
配合使用 -
去除
\u3000
使用str.replace(u'\u3000',u' ')
-
去除空格
replace(" ","")
如果校验当前的list项是不是空字符串
sentence_list = []
for i in tem_sentence_list:
if i.strip() !='':
sentence_list.append(i)
去除\x20
# 去除\x20
str = "".join(str.split())