Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
it is showing error
String cannot be of zero length
what can i do?
please help me



C#
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();
    }
}
Posted
Comments
BillWoodruff 10-Nov-14 12:12pm    
Put breakpoints in your code and single-step to locate the error, and then edit your post to tell us where the error occurs.
123456789shaik 10-Nov-14 12:39pm    
the error is in this line please give me the solution

Regex RegExp =new Regex(Search_Str.Replace("","|").Trim(), RegexOptions.IgnoreCase);
ZurdoDev 10-Nov-14 12:19pm    
If you debug it I think you'll find the solution pretty quickly.
Dominic Burford 10-Nov-14 12:21pm    
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 charater.
BillWoodruff 10-Nov-14 12:36pm    
I think that's a good enough diagnosis to be a "solution."

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
 
Share this answer
 
try like this may work
C#
Regex RegExp =new Regex(Search_Str.Replace(" ","|").Trim(), RegexOptions.IgnoreCase);
 
Share this answer
 
v2
Comments
Philippe Mori 10-Nov-14 20:21pm    
Given that OP question make no sense (as mentionned in solution 1), your guest might be right that the user want to replace each space by a |.
Check this line in your code.
C#
Regex RegExp =new Regex(Search_Str.Replace("","|").Trim(), RegexOptions.IgnoreCase);

You are replacing an empty string with a pipe character.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900