I'm having issues reading in a file using Streamreader
in C#
, where the line breaks in the file I am reading in are also being read into my program and causing issues further on in the code.
Below is an example of the file I am trying to read in.
Example,1,2,3
<--- // Trying to skip these lines.
<--- // Trying to skip these lines.
// MY COMMENTS.
Below is the code I am currently using to check for the line breaks.
if (line.StartsWith("//") ||
line.StartsWith("\r\n") ||
line.StartsWith("\n") ||
line.StartsWith("\r") ||
line.StartsWith(" ") ||
line.StartsWith(Environment.NewLine) ||
line.StartsWith(Environment.NewLine) ||
line.StartsWith($" {Environment.NewLine}")) {
// SKIP THE LINE.
break;
}
// ADD TO ARRAY
I have tried checking for
line.StartsWith("")
in theif statement
, but this results in no values being added to my array.
What needs to be changed for me to skip these lines?
https://msdn.microsoft.com/en-us/library/system.io.streamreader.readline(v=vs.110).aspx
A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"), or a carriage return immediately followed by a line feed ("\r\n"). The string that is returned does not contain the terminating carriage return or line feed. The returned value is null if the end of the input stream is reached.
This article may help: http://www.dotnetperls.com/empty-string
And try with line.IsNullOrEmpty()
(assuming there's no other hidden whitespace on the line you read in).
In theory, every string 'starts with' nothing, so "" would be matched with every line/string you read in.
if ("Hello, World!".StartsWith(""))
Console.WriteLine("Hello, World!");
return;
Prints out the statement.