0

I have a text file that I need to parse. I need to be able to check the result of a line if it has char(28)char(13)...when read lines via below it strips out the control characters and gives me an empty string...Is there a better way to search for control charcters in a file?

var _endMessage = string.Format("{0}{1}", Convert.ToChar(28).ToString(), Convert.ToChar(13).ToString());
foreach (string line in File.ReadLines(_logFile.FullName))
{
    if (Regex.Match(line, _endMessage)
    {
        // Do something here
    }
}

Thanks

swandog
  • 159
  • 1
  • 2
  • 6
  • The various `Read(All)Line(s)` method eat the newline (10, `\n`) and carriage return (13, `\r`) characters. See http://stackoverflow.com/questions/12119393/read-text-file-and-keep-formatting, http://stackoverflow.com/questions/13520472/how-to-read-a-file-into-a-string-with-cr-lf-preserved. You can use `ReadLines()` and just determine that a line ends in character 28, but only if your lines don't suddenly end in `\n` (10) and you wish to detect that and treat it differently. You need to explain more about your format. – CodeCaster Aug 05 '14 at 20:02
  • See [ASCII non readable characters 28, 29 31](http://stackoverflow.com/questions/5128444/) for details about control character with decimal code value 28 which is the **File Separator**. – Mofi Aug 06 '14 at 05:54

0 Answers0