Click here to Skip to main content
15,885,132 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
After typing some text in ckeditor i am able to see the word count on button click but i need to view the word count while typing only.How can i do this.

Below is my code which gives the word count on button click

ASP.NET
<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>


C#
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();
        }


What I have tried:

how can i get the word count while typing instead of getting the word count on button click
Posted
Updated 2-Feb-17 20:57pm
v2

1 solution

There is a plugin for that. Have you tried it yet? You can find it here: Word Count & Char Count Plugin | CKEditor.com[^]
 
Share this answer
 
Comments
kav@94 3-Feb-17 3:07am    
but i need to do it with c# code that too i need to display the word count while typing text in ck editor

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