What is the best way to convert a string separated by return chars into a List?

前端 未结 6 541
谎友^
谎友^ 2021-01-17 16:46

I need to often convert a \"string block\" (a string containing return characters, e.g. from a file or a TextBox) into List

6条回答
  •  滥情空心
    2021-01-17 17:08

    Hmm. You know that string now has a .Split() that takes a string[] array, right?

    So ...

    string[] lines = data.Split(
        new string[1]{ Environment.NewLine },
        StringSplitOptions.None
    );
    

提交回复
热议问题