如何计算Richtexts行中的字符数? [英] how do I can count the number of characters in richtexts line?

查看:109
本文介绍了如何计算Richtexts行中的字符数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一行中有多少个点.用户将在多行RichText中输入一个字符串.一个函数将计算行中的点数.
如果用户按返回键,则减少点数.
如果另一行中的点不增加点数.

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.

推荐答案

如果您要使用javascript代码,请按以下步骤操作:-
If you want to use javascript code then here you go:-
function CountChar(sender) {
          var str = sender.value;
          var res = str.split("a").length - 1;
          document.getElementById("lblText").innerHTML = res;
      }


现在,TextBox的onkeydown属性调用该函数:-


Now onkeydown property of TextBox call the function:-

<asp:TextBox ID="txtText" runat="server" onkeydown="CountChar(this)" />



祝你好运



Good luck


您可以使用以下代码:-
You can use this code:-
string str = txtText.Text;
int res = str.Length - str.Replace(".", "").Length;
lblText.Text = res.ToString();


或者您可以使用linq的"Count"扩展方法,


Or you can use linq ''Count'' extension method,

string str = txtText.Text;
int res = str.ToCharArray().Count(c => c == '.');
lblText.Text = res.ToString();



祝您好运



Good luck


尝试使用javascript函数,并在onkeydown事件中调用此函数.
Try funtion in javascript and call this funtion in onkeydown event.
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");
        }



谢谢
AShish



Thanks
AShish


这篇关于如何计算Richtexts行中的字符数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆