其中页面a中的this.textbox1.text可以输入参数 点击提交后传到另一个页面,传递的参数为“title like % this.textbox1.text %”,传到页面b中,页面b对字符串进行处理
int a = strwhere.IndexOf("%");
            int b = strwhere.LastIndexOf("%");
            guanjianzi = strwhere.Normalize().Substring(a + 1, b - a - 1);
问题是当我在页面a输入中文时,可以运行,
当我输入数字或字母时,却提示 我
“ 长度不能小于 0。
参数名: length ”
求高手帮忙。

解决方案 »

  1.   

    public string Substring(
    int startIndex,
    int length
    )
    startIndex
    类型:System..::.Int32此实例中子字符串的起始字符位置(从零开始)。length
    类型:System..::.Int32子字符串中的字符数。返回值
    类型:System..::.String一个 String,它等于此实例中从 startIndex 开始的长度为 length 的子字符串,如果 startIndex 等于此实例的长度且 length 为零,则为 Empty。
      

  2.   

    “title like % this.textbox1.text %”,
    长度算错啦,%后面不要留空格
      

  3.   

    “title like % this.textbox1.text %”改为"title like %"+ this.textbox1.text +"%"
      

  4.   

    title like % this.textbox1.text %”改为"title like %"+ this.textbox1.text +"%"
    这个源 代码中是这样写的,在这里我为了省事,省略了
      

  5.   

    "title like '%"+ this.textbox1.text +"%'"   应该是这样
      

  6.   

     先看这两个值是几多 a + 1, b - a - 1 你输入中文是因为在跳转时自动 HtmlEncode 了,就变长了,估计就够数了。按个不与中文/数字/字母有关
      

  7.   

     protected void Page_Load(object sender, EventArgs e)
        {
            string strwhere = "title like %aaaaaaaa%";
            int a = strwhere.IndexOf("%");
            int b = strwhere.LastIndexOf("%");
            string guanjianzi = strwhere.Normalize().Substring(a + 1, b - a - 18);    }
    测试是没问题的,你调试下strwhere 值是什么? “%”不会也包含在你传入的字符串里吧?
      

  8.   

     guanjianzi = strwhere.Normalize().Substring(a + 1, b - a - 1);这里的问题
      

  9.   

    我的也出现长度不能小于 0。 参数名: length 
    是多了一个空格的,
    要不你也把多余的空格删掉试试哈