【问题标题】:How to Count numbers of line, word and characters from Edittext field in Android [closed]如何计算 Android 中 Edittext 字段中的行数、单词数和字符数[关闭]
【发布时间】:2015-08-28 02:46:00
【问题描述】:

我是初学者,我想制作一个简单的应用程序来计算我们在 Editext 字段中输入的任何内容的行数、​​单词数和字符数。我想要这样的结果:

EditText : 我的名字是 abc。

按钮点击---->

结果:

没有。字数:4 字符数:14 行数:1

【问题讨论】:

    标签: android java-io


    【解决方案1】:

    首先获取 Edittext 值。然后像 java word counter 那样做

    EditText e1=(EditText) findViewById(R.id.youredittextid);
    String mytext=e1.getText().toString();
    

    为 mytext

    应用 java 代码

    【讨论】:

      【解决方案2】:

      edittext 中的行可能因设备而异.... 对于文字:

      char ch[]= new char[s.length()];      //in string especially we have to mention the () after length
          for(i=0;i<s.length();i++)
          {
              ch[i]= s.charAt(i);
              if( ((i>0)&&(ch[i]!=' ')&&(ch[i-1]==' ')) || ((ch[0]!=' ')&&(i==0)) )
              c++;
          }
      

      对于字符:s.length()

      【讨论】:

        猜你喜欢
        • 2014-02-20
        • 2018-06-02
        • 1970-01-01
        • 2016-08-25
        • 1970-01-01
        • 2022-01-06
        • 1970-01-01
        • 2013-05-19
        • 1970-01-01
        相关资源
        最近更新 更多