开发者

How to fill combobox with text file item!

开发者 https://www.devze.com 2023-03-05 07:22 出处:网络
I have a text file which contain following type item wett45456,4556,45657,898 tyu5878,4566,7989开发者_如何学JAVA,55565

I have a text file which contain following type item

wett45456,4556,45657,898

tyu5878,4566,7989开发者_如何学JAVA,55565

now i have a windowform on that form ihave a combobox now i want fill combobox with firstitem of each row wett45456,tyu5878

Thank you


string[] lineOfContents = File.ReadAllLines("Myfile.txt");
foreach (var line in lineOfContents)
{
   string[] tokens = line.Split(',');
   comboBox1.Items.Add(tokens[0]);
}


It is another solution with Regular Expressions

        string txt = System.IO.File.ReadAllText("file.txt");

        System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(@"[A-Za-z0-9]+");
        foreach(System.Text.RegularExpressions.Match m in rx.Matches(txt))
        {
            If(m.Value.Trim().length>0)
                MyComboBox.Items.Add(m.Value);
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消