How to remove last line in .txt file before appending another file to it

I’ve ran into something I can’t quite figure out. The last line of my .txt file is nothing but white space, Previous line had a CRLF. I am appending another file to this one to create one file. But the output file created has that one blank line in it midway through the final combined file. It appears to be the last line of file1. I’ve tried to use regular expressions to omit writing that line out, but nothing seems to work.

Try This to remove empty lines in your Text file -

Assuming strText is the text extracted from reading the text file
then
strText = String.Join(vbcrlf, strText.Split({vbcrlf}, StringSplitOptions.RemoveEmptyEntries).Where(function(x) not String.IsNullorWhiteSpace(x)))

Then you can write strText back to your text file.

2 Likes

This worked perfectly!!! thanks so much Robot master! :dizzy: :ok_hand:

1 Like

Hi buddy,
Thanks for the appreciation. Can you mark my reply as solution.