标签: java string line-breaks
给定一个字符串我需要检查是否有多个换行符(\ n)。如果我需要将它们转换为单个换行符。
你能告诉我这样做的代码吗?谢谢!
答案 0 :(得分:6)
试试这个
s = s.replaceAll("(\r?\n){2,}", "$1");