سؤال

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