سؤال

HI I need a little help.

Part of my Problem:

  • First, Read a text file.
  • Add the items from text file into TextBox and ListBox.

Sample Data in my text file is like this:

A;Cat;Dog;Rat;Bird

Where, ";" is the Delimiter and data is just one line only.
"A" has to load in TextBox and "Cat,.....,Bird" has to load in ListBox, one line per animal. I've already read the text file and load "A" into text box.
But couldn't figure out how to load rest of the data into list box.

Any help would be great.

هل كانت مفيدة؟

المحلول

This is really simple and you should have a look at the MSDN page to learn more on ListBox and other related stuff.

Dim str As String = "A;Cat;Dog;Rat;Bird"  'should have read from your text file

Dim arr As String() = str.Split(New Char() {";"})
Dim i As Integer
For i = 1 To arr.Length - 1
     ListBox1.Items.Add(arr(i))
Next i

نصائح أخرى

string[] strArrr = "A;Cat;Dog;Rat;Bird".Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        for (int i = 1;i< strArrr.Length - 1; i++)
        {
           listbox.items.add(strarrr[i]);
        }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top