Split text with '\r\n'

前端 未结 8 406
予麋鹿
予麋鹿 2020-12-28 12:42

I was following this article

And I came up with this code:

string FileName = \"C:\\\\test.txt\";

using (StreamReader sr = new StreamReader(FileNam         


        
相关标签:
8条回答
  • 2020-12-28 13:06

    I took a more compact approach to split an input resulting from a text area into a list of string . You can use this if suits your purpose.

    the problem is you cannot split by \r\n so i removed the \n beforehand and split only by \r

    var serials = model.List.Replace("\n","").Split('\r').ToList<string>();
    

    I like this approach because you can do it in just one line.

    0 讨论(0)
  • 2020-12-28 13:08

    This worked for me.

    using System.IO;
    
    //  
    
        string readStr = File.ReadAllText(file.FullName);          
        string[] read = readStr.Split(new char[] {'\r','\n'},StringSplitOptions.RemoveEmptyEntries);
    
    0 讨论(0)
提交回复
热议问题