How to remove empty/new line from text? with split string method

Hi,
I’m trying to remove empty lines from string, but failed.
Example string:
"The number of days working:

12

Total number of leave:

NA"

Please check the above string format, can anyone help me with this using split string?

Assign a variable to System.Text.RegularExpressions.Replace(MyVar, "\n+", "\n"), where MyVar is the variable containing your string above.

This will remove lines which contain nothing but a single newline. The result would look like:

“The number of days working:
12
Total number of leave:
NA”

2 Likes

@Anthony_Humphries previously I was using regex and getting exact output,
Now, I want to do same operations using Split method. Please help.
"The number of days working:12
Total number of leave: NA”

Hi @Palaniyappan , can you please help me with this?

YourArray = YourString.Split(vbNewLine.ToArray, StringSplitOptions.RemoveEmptyEntries)
FinalString = String.Join(vbNewLine, YourArray)

3 Likes

@Dongjin_Lee it works but can you modify the flow? here,I want to remove empty space after “:” and it should replace by the next line text.(use Split method). .
MyString:
"Number of days working:

12

Number of leave:

NA"

My expected output:
"Number of days working:12
Number of leave: NA”

Thanks in advance
Removing_empty_Lines (1).xaml (10.1 KB)

I’m not sure about using split. I think regex will be better in your case
Removing_empty_Lines.xaml (7.9 KB)