문제

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!

도움이 되었습니까?

해결책

try this

s = s.replaceAll("(\r?\n){2,}", "$1");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top