【问题标题】:How to count word in TextView Android Studio [duplicate]如何在TextView Android Studio中计算单词[重复]
【发布时间】:2021-10-25 15:31:15
【问题描述】:

假设在我的应用程序中,我有两个 textview,第一个名称是 ViewText,第二个名称是 WordCount

我想在ViewText 中显示一些文字,而WordCount 显示ViewText 中的字数。

如何在 Android Studio 的 textview 中计算字数?

【问题讨论】:

  • 只计算空格(' ')并添加一个
  • 我相信这个答案会有所帮助:stackoverflow.com/questions/55426910/…
  • @Selvin 请解释一下
  • 非常感谢@Ido Barnea
  • 计数:动词。 1a : 以单位或组来表示或命名,以求出所涉及的单位总数 .... 空格:ASCII 中的 32 位十进制代码字符 .... 加:将(两个或多个数字或数量)组合为加法...一:这是一个数字

标签: android android-studio kotlin android-layout textview


【解决方案1】:

试试这个

val words = "Hi this is sentence for counting words"
var totalCount = words.split("\\s+".toRegex()).size
println(totalCount)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-31
    • 1970-01-01
    • 2019-10-16
    • 2013-12-06
    • 2011-04-25
    • 1970-01-01
    相关资源
    最近更新 更多