字符串长度不能为零。参数名称:oldValue [英] String cannot be of zero length. Parameter name: oldValue

查看:2470
本文介绍了字符串长度不能为零。参数名称:oldValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示错误

字符串长度不能为零

我该怎么办?

请帮帮我







it is showing error
String cannot be of zero length
what can i do?
please help me



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

public partial class Add_Details : System.Web.UI.Page
{
    private string Searchstring = "";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string HighlightText(string InputTxt)
    {
        string Search_Str = txtSearch.Text;
        Regex RegExp =new Regex(Search_Str.Replace("","|").Trim(), RegexOptions.IgnoreCase);
        return RegExp.Replace(InputTxt, new MatchEvaluator(Replacekeywords));

    }
    public string Replacekeywords(Match m)
    {
        return ("<span class=highlight>" + m.Value + "</span>");
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Searchstring = txtSearch.Text;

    }
    protected void clear_Click(object sender, EventArgs e)
    {
        txtSearch.Text = "";
        Searchstring = "";
        gvDetails.DataBind();
    }
}

推荐答案

您会期待什么?你真的试图用一些其他字符串替换某些字符串中的所有空子字符串。你能看到它的荒谬吗?这样的任务是未定义的,无法完成。这种变化的整个概念没有任何意义。



-SA
What would you expect? You literally try to replace "all empty sub-strings in some string with some other string". Can you see the absurdity of it? Such task is something undefined and cannot be accomplished. The whole notion of such change set makes no sense.

—SA


试试这样可以工作

try like this may work
Regex RegExp =new Regex(Search_Str.Replace(" ","|").Trim(), RegexOptions.IgnoreCase);


检查代码中的这一行。

Check this line in your code.
Regex RegExp =new Regex(Search_Str.Replace("","|").Trim(), RegexOptions.IgnoreCase);



您正在用管道字符替换空字符串。


You are replacing an empty string with a pipe character.


这篇关于字符串长度不能为零。参数名称:oldValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆