<body> <form id="form1" runat="server"> <div> <CKEditor:CKEditorControl ID="CKEditor1" BasePath="/ckeditor/" runat="server"> </CKEditor:CKEditorControl> <asp:Button ID="btn1" runat="server" OnClick="btn1_Click" Text="Get Word Count" /> <asp:Label ID="lbl1" runat="server"></asp:Label> </div> </form> </body>
protected void Page_Load(object sender, EventArgs e) { } protected void btn1_Click(object sender, EventArgs e) { string whole_text = CKEditor1.Text; string trimmed_text = whole_text.Trim(); // new line split here string[] lines = trimmed_text.Split(Environment.NewLine.ToCharArray()); // don't need this here now... //string[] split_text = trimmed_text.Split(' '); int space_count = 0; string new_text = ""; foreach (string line in lines) { // Modify the inner foreach to do the split on ' ' here // instead of split_text foreach (string av in line.Split(' ')) { if (av == "") { space_count++; } else { new_text = new_text + av + ","; } } } new_text = new_text.TrimEnd(','); // use lines here instead of split_text lines = new_text.Split(','); //MessageBox.Show(lines.Length.ToString()); lbl1.Text = lines.Length.ToString(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)