FormatException .....你看下 fileNames[i+1].Substring(17,2)) 结果是什么先 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 行 75: int fileNamesNum1 = Convert.ToInt32(fileNames[i+1].Substring(17,2));行 76:把断点设在这里,看看什么错误! 不怎么会设断点查看,我把那行设为断点了,怎么查看fileNames[i+1].Substring(17,2))的结果啊? 你确定 fileNames 的长度超过了19么?如果fileNames长度少于19的话,这里就肯定会出现异常。 鼠标将焦点设在那一行:76行,然后按F9,F5进行调试,到了那一步的时候查看fileNames[i+1].Substring(17,2)的值 在Substring前一定要判断一下长度1、看下str.Substring()越界2、看一下你的取值是否能转化成Int 应该是不行,FormatException转化异常时触发 fileNames[i]都是这样的文件:"E:\001\201004271110.xls",文件名不同而已; for (int i = 0; i < fileNames.Length - 1; i++) { int filePathNum = Convert.ToInt32(filePath.Substring(17, 2)); int fileNamesNum = Convert.ToInt32(fileNames[i].Substring(17,2)); int fileNamesNum1 = Convert.ToInt32(fileNames[i+1].Substring(17,2)); }str.Substring()不会越界吧,而且肯定是能转换为Int的,具体的代码是这样的: protected void btnOK_Click(object sender, EventArgs e) { string dir = @"E:\"; string monitorID = DropDownListMonitor.SelectedValue; string pathMonitor = dir + monitorID; string[] fileNames = Directory.GetFiles(pathMonitor); string filePath = getFilePath(); for (int i = 0; i < fileNames.Length - 1; i++) { if (filePath == fileNames[i]) { lblFilePath.Text = "您查找的文件为:" + filePath.Substring(7, 16); break; } else if ((filePath != fileNames[i]) && (filePath.Substring(0, 17) == fileNames[i].Substring(0, 17))) { int filePathNum = Convert.ToInt32(filePath.Substring(17, 2)); int fileNamesNum = Convert.ToInt32(fileNames[i].Substring(17, 2)); int fileNamesNum1 = Convert.ToInt32(fileNames[i + 1].Substring(17, 2)); if (Math.Abs(filePathNum - fileNamesNum) < Math.Abs(filePathNum - fileNamesNum1)) { lblFilePath.Text = "您查找的文件不存在,这个是最接近的文件:" + fileNames[i].Substring(7, 16); break; } } else { lblBack.Text = "没有符合条件的文件,请继续查找。"; } } }我把它放在下面,就不会报错。 c#中用了mdiparent以后menuStrip使用会失效怎么办?? c#生成XML 关于Form背景图片的问题,请各位大哥都进来坐坐 第三方控件的知识 急急如律令 超简单我不知道是那个函数帮顶有分 如何去掉分词结果中的停用词? 有誰開發過通信程序 IE奇怪的问题..偶不想重装系统啊!! SqlConnection 连接类支持多线程吗? 好郁闷好郁闷好郁闷~ 查了.NET Framework文档,明明有System.Web.UI命令时间,放到程序里编译说找不到??? 初学者求助,WEB服务器不是ASP.NET1.1版本 如何用 MSNPSharp 实现向任意一个MSN用户发信息
for (int i = 0; i < fileNames.Length - 1; i++)
{
int filePathNum = Convert.ToInt32(filePath.Substring(17, 2));
int fileNamesNum = Convert.ToInt32(fileNames[i].Substring(17,2));
int fileNamesNum1 = Convert.ToInt32(fileNames[i+1].Substring(17,2));
}
str.Substring()不会越界吧,而且肯定是能转换为Int的,具体的代码是这样的: protected void btnOK_Click(object sender, EventArgs e)
{
string dir = @"E:\";
string monitorID = DropDownListMonitor.SelectedValue;
string pathMonitor = dir + monitorID;
string[] fileNames = Directory.GetFiles(pathMonitor);
string filePath = getFilePath(); for (int i = 0; i < fileNames.Length - 1; i++)
{
if (filePath == fileNames[i])
{
lblFilePath.Text = "您查找的文件为:" + filePath.Substring(7, 16);
break;
}
else if ((filePath != fileNames[i]) && (filePath.Substring(0, 17) == fileNames[i].Substring(0, 17)))
{
int filePathNum = Convert.ToInt32(filePath.Substring(17, 2));
int fileNamesNum = Convert.ToInt32(fileNames[i].Substring(17, 2));
int fileNamesNum1 = Convert.ToInt32(fileNames[i + 1].Substring(17, 2)); if (Math.Abs(filePathNum - fileNamesNum) < Math.Abs(filePathNum - fileNamesNum1))
{
lblFilePath.Text = "您查找的文件不存在,这个是最接近的文件:" + fileNames[i].Substring(7, 16);
break;
}
}
else
{
lblBack.Text = "没有符合条件的文件,请继续查找。";
}
}
}我把它放在下面,就不会报错。