How to add lines of a text file into individual items on a ListBox (C#)

前端 未结 4 1889
渐次进展
渐次进展 2021-01-23 00:52

How would it be possible to read a text file with several lines, and then to put each line in the text file on a separate row in a ListBox?

The code I have so far:

4条回答
  •  礼貌的吻别
    2021-01-23 01:17

    String text = File.ReadAllText("ignore.txt");
    
    var result = Regex.Split(text, "\r\n|\r|\n");
    
    foreach(string s in result)
    {
      lstBox.Items.Add(s);
    }
    

提交回复
热议问题