判断textbox中的值能否存在去listbox中(textbox的值之间用“->“连接),大家看看逻辑对吗?
app = (IvcApplication)new vc3DCreate.vcc3DCreate(); for (int c = 0; c < app.ComponentCount; c++) { IvcComponent comp = app.getComponent(c); object name = comp.getProperty("Name"); listBox1.Items.Add(name); } [color=#00FF00]string[] t = textBox5.Text.Split("->".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);//分割textbox 的值 int xxx = 0;//计数xxx for (int idx = 0; idx < t.Length; idx++) { foreach (var item in listBox1.Items) { if ((item.ToString()) == (t[idx]))//当存t中值存在于list,计数变量加1 { xxx += 1; } } } if (xxx == t.Length)//说明text的值都存在于listbox中 { //执行操作 } else { //提示错误 }
解决方案
40
textBox1.Text.Split(“->”.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
->
textBox1.Text.Split(new string[] { “->” }, StringSplitOptions.RemoveEmptyEntries);
->
textBox1.Text.Split(new string[] { “->” }, StringSplitOptions.RemoveEmptyEntries);