将文本文件加载到列表框中 [英] Loading text file into listbox

查看:18
本文介绍了将文本文件加载到列表框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要实现的是将文本文件加载到列表框中.看起来很简单,但是当有新行时我需要在文本文件中识别,并且每个新行都需要是列表框中的一个新项目.

What I am wanting to achieve is loading a text file into a listbox. It seems simple enough but I need to recognise in the text file when there is a new line, and each new line needs to be a new item in the listbox.

如果可以的话,我们将不胜感激.

If this is possible, a reply would be much appreciated.

推荐答案

这样就可以了

List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(f))
{
    string line;
    while ((line = r.ReadLine()) != null)
    {
        lines.Add(line);
    }
}

这篇关于将文本文件加载到列表框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆