Dot NET
Dot NET

Reputation: 4897

Reading text file one line at a time

I have got a text file with a number of commands to parse through my system. Each line within the text file is a command.

I would like to read the text file, one line at a time, where each line would be a command for me to act on.

I have reached a state where some lines are read completely by using StreamReader.ReadLine(), however some lines are not read completely. Within notepad, there appears to be nothing wrong with the commands, and each one appears in one line like it is supposed to.

However, when opening the file with notepad++, I notice LF symbols within some commands, which instructs the text editor to start a new command, like so:

enter image description here

Those LF are misplaced (i.e. I do not want to start a new line when the LF is part of a command). Is there any way to make the StreamReader interpret the file like Notepad? As there are no line breaks in the middle of commands within Notepad.

Upvotes: 0

Views: 916

Answers (1)

Hassan
Hassan

Reputation: 5430

If all text is one line then you could skip using StreamReader. Instead you can use

string sLine = File.ReadAllText("test.txt");
sLine = sLine.Replace("\n", "");

Upvotes: 3

Related Questions