【发布时间】:2017-09-21 11:30:35
【问题描述】:
经过彻底搜索,我可以找到如何删除特定字母之前的所有字符,而不是 any 字母之前的所有字符。
我正在尝试从中转换一个字符串:
" This is a sentence. #contains symbol and whitespace
到这里:
This is a sentence. #No symbols or whitespace
我试过下面的代码,但是还是会出现第一个例子这样的字符串。
for ch in ['\"', '[', ']', '*', '_', '-']:
if ch in sen1:
sen1 = sen1.replace(ch,"")
这不仅由于某种未知原因无法删除示例中的双引号,而且也无法删除前导空格,因为它会删除 所有 个空格。
提前谢谢你。
【问题讨论】: