How to fill combobox with text file item!

前端 未结 2 1288
清酒与你
清酒与你 2021-01-13 04:51

I have a text file which contain following type item

wett45456,4556,45657,898

tyu5878,4566,7989,55565

now i have a windowform on that form

相关标签:
2条回答
  • 2021-01-13 05:12

    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 讨论(0)
  • 2021-01-13 05:21
    string[] lineOfContents = File.ReadAllLines("Myfile.txt");
    foreach (var line in lineOfContents)
    {
       string[] tokens = line.Split(',');
       comboBox1.Items.Add(tokens[0]);
    }
    
    0 讨论(0)
提交回复
热议问题