You must Sign In to post a response.
  • Category: .NET

    Regex eliminates hyphen on clicking complete button

    On running my code in the browser i have some templates on clicking those templates below code gets executed

    protected void ShowTemplate(byte[] Template)
    CKEditor1.Text = "";
    byte[] excelContents = Template;
    File.WriteAllBytes(Server.MapPath("~/Doc/") + "Demo.Docx", excelContents);
    string path = Server.MapPath("~/Doc/") + "Demo.html";
    document.SaveToFile(path, Spire.Doc.FileFormat.Html);
    string html = File.ReadAllText(path);
    string[] splits = Request.Url.AbsoluteUri.Split('/');
    string url = string.Empty;
    if (splits.Length >= 2)
    url = splits[0] + "//";
    for (int i = 2; i < splits.Length - 1; i++)
    url += splits[i];
    url += "/";
    string ImgPath = url + "Doc\\Demo_images";
    html = html.Replace("Demo_images", ImgPath);
    string STR = html;
    string STRFirst = "<title>";
    string STRLast = "</title>";
    string FinalString;
    int Pos1 = STR.IndexOf(STRFirst) + STRFirst.Length;
    int Pos2 = STR.IndexOf(STRLast);
    FinalString = STR.Substring(Pos1, Pos2 - Pos1);
    if (FinalString.Length > 0)
    { html = html.Replace(FinalString, ""); }
    string str = @"""0""";
    string str1 = "<table border=" + str + " ";
    html = html.Replace("<table", str1);
    html = html.Replace("border-top-color:", "\"><hr /><border-top-color:");
    CKEditor1.Text = html;
    String TCount = Regex.Replace(CKEditor1.Text, @"<[^>]+>| |"|'| |\n|\r|\t|–|Start here|text here", "");
    ViewState["TCount"] = TCount;

    In this method the text that i get at TCount while debugging iswhen i click on template is

    FILE NOTEClient/Ref:Surname/Date:15 July 2016Matter:Attended by:LCTime engaged:1 hour – .Time engaged – 1 hour

    After clicking the template user can see an editor where he can give the text an click on submit button if the user does not eneter any text in the editor and click on submit button i should get the word count as zero but i am getting word count as -2 because when i click on complete button the text that i get at TCount in the first method is same as second method but it eliminates hyphens as two hyphens are eliminated instead of getting zero as word count i am getting -2 as word count how ca i display hyphens in my second method also near count.

    protected void btnCompleteTranscription_Click(object sender, EventArgs e)
    string count = Regex.Replace(CKEditor1.Text, @"<[^>]+>| |"|'| |\n|\r|\t|–|Start here|text here", "");
    string Text = "<html><body>" + CKEditor1.Text + "</body></html>";
    Text = Text.Replace("<", "<");
    Text = Text.Replace(">", ">");
    Text = Text.Replace(">style=", "><span style=");
    Text = Text.Replace("<span <", "<span></span> <");
    Text = Text.Replace("<p <", "<p> <");
    Text = Text.Replace("<del", "<s><span");
    Text = Text.Replace("</del", "</s></span");
    Text = Text.Replace(" ", " ");
    Text = Text.Replace("<s style=", "<s><span style=");
    Text = Text.Replace("<p <", "<p style=\"text-align:justify\"><span><");
    Text = Text.Replace(">font-size:14pt", " "); ;
    CKEditor1.Text = Text;

    string TCount = ViewState["TCount"].ToString();
    int TLength=(Int32)ViewState["TCount"].ToString().Length;
    int WCount = (Int32)count.Length - TLength;
    string datefolder = DateTime.Today.Month.ToString().Length < 2 ? "0" + DateTime.Today.Month.ToString() : DateTime.Today.Month.ToString();
    datefolder += DateTime.Today.Day.ToString().Length < 2 ? "0" + DateTime.Today.Day.ToString() : DateTime.Today.Day.ToString();
    datefolder += DateTime.Today.Year.ToString();

    string ComparePath = Server.MapPath("~/GDocs/" + Session["uid"].ToString().ToUpper() + "/Transcribed/" + datefolder);
    if (!System.IO.Directory.Exists(ComparePath))
    using (System.IO.StreamWriter file = new System.IO.StreamWriter(ComparePath + @"\" + ViewState["af"].ToString().Replace(".wav", "") + ".Doc"))
    when i click on complete button the text that i get near count is

    FILE NOTEClient/Ref:Surname/Date:15 July 2016Matter:Attended by:LCTime engaged:1 hour .Time engaged 1 hour

    **If we notice those two sentences hyphens gets eliminated in second method but i need to display hyphens also how can i do this**
  • #767640
    Hypens are eliminated cause you have put - hypen in your regex and that will be remove once regular expression get fired
    see below regular expression, it contains hypen after \t, just remove it and your problem get resolved
    Regex.Replace(CKEditor1.Text, @"<[^>]+>| |"|'| |\n|\r|\t|–|Start here|text here", "");

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767644
    can you please edit my post and post the answer which displays hyphens in show template method and btn complete method as i am new to this the regex expression that is used in show template method and btn complete method is same and the text that i get is also same but hyphens are getting eliminated in btn complete method and hyphens are displayed in show template methos near string TCount and string Count sentences and my requirement is i need to display hyphens in btn complete method also how can i do this can anyone help me out

  • #767645
    it is not working using the regex i need to get wordcount as zero if there is no text in ckeditor but i am not getting zero

  • Sign In to post your comments