美文网首页
kotlin 中split

kotlin 中split

作者: 王家匀匀 | 来源:发表于2021-02-03 15:59 被阅读0次

kotlin 中的split 与 java的split还有些不一样。
kotlin.split(" ").针对连续空格, 中间会分割出空字符串
需要改为

 str.split("regex".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()

空格检索可以这样:

        val arr = content.trim().split(" +".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        LogUtils.d(TAG,"arr.size=${arr.size}")

相关文章

网友评论

      本文标题:kotlin 中split

      本文链接:https://www.haomeiwen.com/subject/xqxutltx.html