如何从字符串中删除多个换行符 [英] How to remove multiple line breaks from a string
本文介绍了如何从字符串中删除多个换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定一个字符串我需要检查是否有多个换行符(\ n)。如果我需要将它们转换为单个换行符。
given a string i need to check if there are multiple line breaks (\n). If there are i need to convert them to one single line break.
你能告诉我这样做的代码吗?谢谢!
Can you please show me code that does this? thanks!
推荐答案
试试这个
s = s.replaceAll("(\r?\n){2,}", "$1");
这篇关于如何从字符串中删除多个换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文