Regex not working in getting the exact word count
Below is my code where on running the application the user can first a template and on clicking that template we can see ck editor along with a drop down beside to ckeditor where user can see multiple items on choosing a particular item in drop down the corresponding text in the ckeditor gets changed when user gives nothing in the editor and click on complete button i should get the word count as zero and when user gives any words in the editor i need to get that word count suppose if i give abcd i need to get the count as 4 and if i don't give anything i need to get count as zero but with the current code i am get word count as -2 for first drop down,0 for second drop down,-3 for third drop down and 4 for third drop down when there is no text in the editor i need to get zero but i am getting these as word countsprotected 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;
}
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))
{
System.IO.Directory.CreateDirectory(ComparePath);
}
using (System.IO.StreamWriter file = new System.IO.StreamWriter(ComparePath + @"\" + ViewState["af"].ToString().Replace(".wav", "") + ".Doc"))
{
file.Write(Text);
}
}