从 ListBox 项中提取多个数组值
Extracting multiple array values from a ListBox item
我在列表框中将三个数组放在一行中:
Listbox.Items.Add(array1[i] + "\t" + array2[i] + "\t" + array3[i]);
我希望能够 select 一行,其中包含所有 3 个数组,并且
将三个值(每个数组一个)拆分为 3 个单独的字符串。
现在我可以做到:
string currentSelected = ListBox.GetItemText(ListBox.SelectedItem);
但这给了我一个字符串中的所有 3 个数组值。
你可以使用Split
方法做你想做的事:
string currentSelected = ListBox.GetItemText(ListBox.SelectedItem);
string[] values = currentSelected.Split('\t');
我在列表框中将三个数组放在一行中:
Listbox.Items.Add(array1[i] + "\t" + array2[i] + "\t" + array3[i]);
我希望能够 select 一行,其中包含所有 3 个数组,并且 将三个值(每个数组一个)拆分为 3 个单独的字符串。 现在我可以做到:
string currentSelected = ListBox.GetItemText(ListBox.SelectedItem);
但这给了我一个字符串中的所有 3 个数组值。
你可以使用Split
方法做你想做的事:
string currentSelected = ListBox.GetItemText(ListBox.SelectedItem);
string[] values = currentSelected.Split('\t');