sr=new StreamReader(@"C:\Customer.txt");
string find="";
while((find=sr.ReadLine())!=null)
{
data=sr.ReadLine();
string c=":";
char[] cc=c.ToCharArray();
string[] str=null;
for(int i=1;i<find.Length;i++)
{
str = find.Split(cc,i);
}
if(str[1].Equals(name))
{
MessageBox.Show("hh");
return;
}
}
MessageBox.Show("can not found it!","error");
这段代码中不停报错,说我字符串数组越界,怎么解决?
string find="";
while((find=sr.ReadLine())!=null)
{
data=sr.ReadLine();
string c=":";
char[] cc=c.ToCharArray();
string[] str=null;
for(int i=1;i<find.Length;i++)
{
str = find.Split(cc,i);
}
if(str[1].Equals(name))
{
MessageBox.Show("hh");
return;
}
}
MessageBox.Show("can not found it!","error");
这段代码中不停报错,说我字符串数组越界,怎么解决?
解决方案 »
- GridView 中的ImageField 之 AlternateText 问题
- c# 2010中的默认栈是多大呢?
- WindowsMediaPlayer播放在线音乐
- remoting 传送实体
- 有一个一维数组,如何找出最小的一个数
- 如何通过Timer设置来遍历表中的信息
- treeview 树控件在拖动节点的过程中,如何移动滚动条?
- 如何将DATAGRID限定为只能输入指定行
- Sunmast(速马/Truly Madly Deeply)兄能帮帮我吗!
- 在Datagrid中编辑时出现DropDownList,要求根据datagrid中某列的值选中DropDownList的一项!
- 数据类型溢出问题
- 能发送串口信号的设备
if(str[1].Equals(name))根本就看不懂你的程序,例如:
data=sr.ReadLine();
data哪儿来?干什么用?发个能编译通过的来。
str[]不总是有两个元素,可能只有一个元素。
for(int i=1;i<find.Length;i++)
{
str = find.Split(cc,i);
}
//这里用到了[1],难道你的目的是用[0]????数组是从0开始的。
if(str[1].Equals(name))
{
MessageBox.Show("hh");
return;
}
{
str = find.Split(cc,i);
}
if(str[1].Equals(name))
{
MessageBox.Show("hh");
return;
}
//改
首页cc 要为char 去掉分割限制 你在这里限制 length 为1 在下面用str[1] 明显越界for(int i=1;i<find.Length;i++)
{
str = find.Split(cc);
}
// 加个判断
if(str.Length > 1)
{
if(str[1].Equals(name))
{
MessageBox.Show("hh");
return;
}
}
for(int i=1;i<find.Length;i++)
{
str = find.Split(cc);
}
这是干什么啊 find type is string
string find = "name:tel:address";
for(int i=1;i<find.Length;i++){
str = find.Split(':');
//執行三次
//第一次 str: str[0] name str[1] tel
//第二次同上
//第三次同上
}