Remove empty lines

Hello guys,

I have a problem with remove empty new lines can u guys help me? I have a text like that:

991234637212123;

EmreOguzEmreOguzEmreOguzEmreOguz
EmreOguzEmreOguzEmreOguzEmreOguz

213091024902193;

I want to remove empty newlines between EmreOguz’s and numbers and text should be like that:

991234637212123;
EmreOguzEmreOguzEmreOguzEmreOguz
EmreOguzEmreOguzEmreOguzEmreOguz
213091024902193;

Thank u !

2 Likes

You could use the String.Replace method if you have the text with the lines needing to be removed in a string variable. It should be possible to remove them like:

inputString.Replace(chr(13)+Chr(10)+Chr(13)+Chr(10),chr(13)+chr(10))

This replaces each instance of a double carriage return [chr(13)] and line feed [chr(10)] with a single. Essentially replacing hitting the enter key twice with hitting it once when working in a text editor. This could probably be done with regex as well.

1 Like

@Emre_Oguz

new RegEx(“(\r?\n){2,}”).Replace(strSample,Environment.NewLine)
is replacing 2 or more NewLines with a single newline

grafik

Find Demo here:
RegEx_Replace_MultiLRs.xaml (4.8 KB)

1 Like