Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从字符串中删除多个换行符,这样我只能得到一个换行符(如果有的话)。例如我有一个字符串"\r\n\r\n\r\n\r\n\r\n\r\n\r\n",我怎样才能把它变成一个字符串'\n'?
"\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
'\n'
你可以使用:
myString = myString.replaceAll("[\r\n]+", "\n");
在Android中,我设法用这个删除了两个以上的换行符
textPiece = textPiece.replaceAll("\n\n\n+", "\n\n");