【发布时间】:2020-09-09 09:11:20
【问题描述】:
我正在创建一个网络应用程序,并且我正在使用 IMAP 从电子邮件中读取字符串。
我想从电子邮件中的字符串中删除换行符和回车符。当我完成相关的 IMAP 操作并在字符串上运行 replace("\n","") 时,不幸的是,字符串中仍然有换行符和回车符。我怎样才能解决这个问题?
例如下面代码的输出:
try:
if sender!='craigmac@gmail.com':
msg = str(utilities.refineMSG(str(utilities.get_body(raw)))[2:-44]).replace("\r\n",'')
print(msg)
应该是:
Thanks Craig, but we don\'t focus much on medical devices. In particular, we tend to stay away from implantable surgical devices.\r\n\r\nWe\'ll pass on this one for now, but appreciate the heads up.\r\n\r\nBest-\r\n\r\n-Kyle\r\n\r\nsent from my phone\r
【问题讨论】:
标签: python python-3.x string methods replace