I am trying to figure out how to replace multiple breaks (\n
) with a maximum breaks of two. I used trimmingCharacters(in:) to remove all the white spaces and new lines around the string, but I can't figure out how to remove the space within the string, or rather said: how could I replace more than 2 breaks to be maximum of 2 breaks?
For an instance:
If the user writes in a textView with spaces between the words, the string will be:
"Hello
I like coffee"
The string result I'd like to achieve:
"Hello
I like coffee"