我試圖刪除此字符串中的所有"\n"
。然而,string.strip()
方法並不能完全清除文本strip()並非全部替換 n
body = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nSome text\n\nHow toremovealln?\n\t\t\t\t\tbecause notworking\n\t\t\t\t\t"
body.strip("\n")
結果是
"Some text\n\nHow toremovealln?\n\t\t\t\t\tbecause notworking\n\t\t\t\t\t"
如何將它們全部刪除?
你的問題是什麼? –
'strip'只能去掉前後的字符 – Wondercricket
那麼你到底需要輸出什麼? –