我想使用/
and拆分从 txt 文件中读取的文本*
。
但是,我浏览文件并'Index was outside the bounds of the array.'
出现!
任何帮助,将不胜感激
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string fileToOpen = ofd.FileName;
System.IO.StreamReader sr = new System.IO.StreamReader(fileToOpen);
string fileContent = sr.ReadLine();
string[] items = fileContent.Split('*').ToArray<string>();
string[] buffer;
foreach (string s in items)
{
ListViewItem lv = new ListViewItem();
buffer = s.Split('/').ToArray<string>();
lv.Text = items[0].ToString();
lv.SubItems.Add(items[1].ToString());
lv.SubItems.Add(items[2].ToString());
lv.SubItems.Add(items[3].ToString());
listView1.Items.Add(lv);
lv.Text = buffer[0];
lv.SubItems.Add(buffer[1]);
lv.SubItems.Add(buffer[2]);
listView1.Items.Add(lv);
}
}
是我的代码,谢谢!