Delete Lines Text File Issue

Hi,

I’m having an issue to delete multiple lines in this specific text file (Convert from PDF to text)
I did try to used 2 below command but it cannot delete the lines

  1. dellines=String.Join(System.Environment.Newline, yourstring.Split({System.Environment.Newline},System.StringSplitOptions.RemoveEmptyEntries))

  2. text.Replace(System.Environment.Newline+System.Environment.Newline, System.Environment.Newline)

Other file if I create manually no issue I can delete multiple lines but on this files cannot.
Anybody can help on this.

Regards

Untitled2.txt (4.2 KB)

just let us know the criteria which will applied for deleting the lines

Just delete the blank line
Before

ETIQA CLAIM

6629156

Output result expected as below for all the space in the file.

ETIQA CLAIM
6629156

e.g

ETIQA CLAIM
6626424
01/04 CMS - CR PYMT MARS 199.00+ 1,001,279.12
ETIQA FAMILY TAKAFUL
ETIQA CLAIM

6629156
01/04 CMS - CR PYMT MARS 199.00+ 1,001,478.12
ETIQA FAMILY TAKAFUL
ETIQA CLAIM
6629152
01/04 CMS - CR PYMT MARS 127.00+ 1,001,605.12
ETIQA FAMILY TAKAFUL

Suppose it should combine to the next line

ETIQA CLAIM
6626424
01/04 CMS - CR PYMT MARS 199.00+ 1,001,279.12
ETIQA FAMILY TAKAFUL
ETIQA CLAIM
6629156
01/04 CMS - CR PYMT MARS 199.00+ 1,001,478.12
ETIQA FAMILY TAKAFUL
ETIQA CLAIM
6629152
01/04 CMS - CR PYMT MARS 127.00+ 1,001,605.12
ETIQA FAMILY TAKAFUL

Change the code to:

String.Join(System.Environment.Newline, yourstring.Split(System.Environment.Newline.ToCharArray,System.StringSplitOptions.RemoveEmptyEntries))

Explanation: Your text contains a mix of CR and CRLF as line breaks. In Windows a line break consists of two characters (System.Environment.Newline = CRLF).

image

1 Like

Hi @Abang_Jamuri_Abang_Shoker,

Could you please try this: String.join("", Split(text, vblf+vbcr).Select(function (x) x.Trim))

Hope this helps.

Thanks,
Ashwini Kempraj

when empty lines from a specific text file are to remove we can do following:

arrLines | String( ) - a String Array =
File.ReadAllLines(YourFullFilePath)

arrLinesFiltered | String( ) - a String Array =
arrLines.Where(Function (x) Not String.IsNullOrEmpty(x.Trim)).toArray

strFilteredText = String.Join(Environment.NewLine, arrLinesFiltered)

As an Alternate we also can remove with regex Multiple following Linebreaks as they are representing empy lines

Manage to delete and combine all the lines.
Thank you very much for your explanation and help.
By the way what software did you used to get the details ( CR and CRLF information)

Regards

thank you ashwini your command also can delete and combine the lines.

1 Like

I used Notepad++.

thank you for the info

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.