翻到最后一页就会出现下面的错误,而其它页均正常!请高手指点,谢谢!!! ——————————————————————————————————————————————————————————————————————————— 索引和长度必须引用该字符串内的位置。参数名: length
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。参数名: length 源错误:
行 9: </tr>
行 10: <tr>
行 11: <td height="25"> <%# getComment( DataBinder.Eval(Container.DataItem, "Content"))%> </td> ----------------------------------------------------------------------------------------------------
getcomment的代码如下: public string getComment(object Content)
{
string input = Content.ToString();
input = new Regex("\r\n", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <span[ ]{0,}(.)*?>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" </p>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" </span>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <img[ ]{0,}(.)*?>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" ", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <br>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <[ ]{0,}(.)*?>", RegexOptions.IgnoreCase).Replace(input, "");
string[] strArray = base.Request.QueryString["keyword"].Split(new char[] { ' ' });
int index = 0;
Regex regex9 = new Regex("");
for (int i = 0; i < strArray.Length; i++)
{
if (strArray[i] != "")
{
input = new Regex(strArray[i], RegexOptions.Compiled ¦ RegexOptions.IgnoreCase).Replace(input, " <font color=\"red\">" + strArray[i] + " </font>");
if (input.IndexOf(strArray[i]) > 0)
{
index = input.IndexOf(strArray[i]);
}
}
}
try
{
if (index >= 20)
{
return input.Substring(index - 20, 100);
}
if (input.Length >= 100)
{
return input.Substring(0, 100);
}
return input;
}
catch
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。参数名: length 源错误:
行 9: </tr>
行 10: <tr>
行 11: <td height="25"> <%# getComment( DataBinder.Eval(Container.DataItem, "Content"))%> </td> ----------------------------------------------------------------------------------------------------
getcomment的代码如下: public string getComment(object Content)
{
string input = Content.ToString();
input = new Regex("\r\n", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <span[ ]{0,}(.)*?>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" </p>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" </span>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <img[ ]{0,}(.)*?>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" ", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <br>", RegexOptions.IgnoreCase).Replace(input, "");
input = new Regex(" <[ ]{0,}(.)*?>", RegexOptions.IgnoreCase).Replace(input, "");
string[] strArray = base.Request.QueryString["keyword"].Split(new char[] { ' ' });
int index = 0;
Regex regex9 = new Regex("");
for (int i = 0; i < strArray.Length; i++)
{
if (strArray[i] != "")
{
input = new Regex(strArray[i], RegexOptions.Compiled ¦ RegexOptions.IgnoreCase).Replace(input, " <font color=\"red\">" + strArray[i] + " </font>");
if (input.IndexOf(strArray[i]) > 0)
{
index = input.IndexOf(strArray[i]);
}
}
}
try
{
if (index >= 20)
{
return input.Substring(index - 20, 100);
}
if (input.Length >= 100)
{
return input.Substring(0, 100);
}
return input;
}
catch
错误应该出在这。这个100从那来,可能就是100的问题。
input.length应该小于100
if (input.Length >= 100)和input.Substring(0, 100);矛盾
input.Length如果等于100是表示可以放100个字符
input.Substring(0, 100)中第一个字符的索引是0所以是99才对
你再试试