Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Kotlin-处理EditText中的名称_Android_String_Kotlin - Fatal编程技术网

Android Kotlin-处理EditText中的名称

Android Kotlin-处理EditText中的名称,android,string,kotlin,Android,String,Kotlin,我有两个EditText,输入类型为android:inputType=“textPersonName | textCapWords” 用户可能会输入他们的名字(“John Doe”),这将保存到Firestore 我相信textPersonName | textCapWords将处理名称中首个字符的大写,但是,我想处理一种情况,即用户在其名称(“John Doe”)之间放置的空格过多 我曾想过这样做: val splitCMName = caseManager.split(" &qu

我有两个EditText,输入类型为android:inputType=“textPersonName | textCapWords”

用户可能会输入他们的名字(“John Doe”),这将保存到Firestore

我相信
textPersonName | textCapWords
将处理名称中首个字符的大写,但是,我想处理一种情况,即用户在其名称(“John Doe”)之间放置的空格过多

我曾想过这样做:

val splitCMName = caseManager.split(" ")

    val joinedCMName = splitCMName.joinToString {
        splitCMName[0] + " " + splitCMName[splitCMName.lastIndex]

    })
然而,我想知道如何以更为Kotlin/Android Studio的方式实现这一点,如果有的话。我认为我的方法可能太过霸道了


如有任何建议,我将不胜感激。谢谢。

使用正则表达式将所有空格替换为单个空格字符怎么样

val normalized = caseManager.replace(Regex("\\s+"), " ")

本!非常感谢你!这给了我想要的输出。