I have a string in C# which can have multiple \n
characters. For e.g. :
string tp = "Hello\nWorld \n\n\n !!";
If there is a single occurrence of \n
I want to replace it with something, but if more than one \n
appear together in the same place I want to leave them alone. So for the tp
string above I want to replace the \n
between Hello
and World
, because there is only one at that place, and leave the the three \n
nearer the end of the string alone, because they appear in a group.
If I try to use the Replace()
method in C# it replaces all of them. How can I resolve this issue?