1

So I am reading a text file which may or may not end with some lines ending 9999999999999999999999999

which are just extra lines to make up a batch...im reading in the file like this

var lines = 
 File.ReadAllLines("C:\\Users\\Downloads\\EmployeeExpenseReimbACH_20111214.txt");

How can I loop through this and remove the lines with 9999999's? and then end up with an array without them basically.

0

1 Answer 1

1

You can use LINQ:

using System.Linq;

var path = "C:\\Users\\Downloads\\EmployeeExpenseReimbACH_20111214.txt";
var lines = File.ReadAllLines(path).Where(x => !x.EndsWith("99999"));
Sign up to request clarification or add additional context in comments.

3 Comments

And if the line only has 999?
OP stated that the lines end with 9999999999999999999999999. And I assume he'd be able to determine whatever argument he needs to supply to EndsWith to make sure any lines will be removed that need to be. Why should I make the answer more complicated than required?
Yes, definitely dive into LINQ. It can make life so much easier sometimes. Glad I could help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.