Stream Reader Readline detect newline characters

后端 未结 3 549
无人共我
无人共我 2021-01-16 17:19

I\'m trying to remove any \"new line\" characters from each line of text in my log file.

Below is an example entry that I am reading in with a Stream Reader :-

3条回答
  •  囚心锁ツ
    2021-01-16 17:50

    sr.ReadLine().Replace(Environment.NewLine, String.Empty);
    

    EDIT: In case the end of line is not \r\n but \n you can use regex:

    Line = Regex.Replace(sr.ReadLine(), @"(\r\n|\n)", String.Empty);
    

提交回复
热议问题