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

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

问题描述

我想实现的是加载文本文件转换成一个列表框什么。这似乎很简单,但我需要在文本文件中承认的时候有一个新的生产线,而每个新行需要在列表框中的新项目。

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天全站免登陆