Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to know how many dot in a line.User'll enter a string in multipleline richtext.A function will count the number of dots in rows.
If User press back key,reducing the number of dots.
If the dot in another line,does not increase the number of dots.
Posted

If you want to use javascript code then here you go:-
JavaScript
function CountChar(sender) {
          var str = sender.value;
          var res = str.split("a").length - 1;
          document.getElementById("lblText").innerHTML = res;
      }

Now onkeydown property of TextBox call the function:-
ASP.NET
<asp:TextBox ID="txtText" runat="server" onkeydown="CountChar(this)" />


Good luck
 
Share this answer
 
v2
Comments
giatuan2011 28-Jul-12 1:09am    
How to reduce Count when I hit back or delete dots?
Raje_ 28-Jul-12 7:24am    
you can use javascript for that, see my updated solution.
You can use this code:-
C#
string str = txtText.Text;
int res = str.Length - str.Replace(".", "").Length;
lblText.Text = res.ToString();

Or you can use linq 'Count' extension method,
C#
string str = txtText.Text;
int res = str.ToCharArray().Count(c => c == '.');
lblText.Text = res.ToString();


Good luck
 
Share this answer
 
v3
Try funtion in javascript and call this funtion in onkeydown event.
JavaScript
function textCounter(field,countfield,maxlimit)
        {
        //alert(maxlimit);
            if(field.value.length>maxlimit)
            field.value=field.value.substring(0,maxlimit);
            else
            countfield.value=maxlimit - field.value.length;
            if(countfield.value==0)
            alert("Maxlimit is over");
        }


Thanks
AShish
 
Share this answer
 
Comments
[no name] 28-Jul-12 0:16am    
A javascript answer to a C# question?

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