Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.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 以逗号分隔的字符串打印所有元素_Android_String_Kotlin - Fatal编程技术网

Android 以逗号分隔的字符串打印所有元素

Android 以逗号分隔的字符串打印所有元素,android,string,kotlin,Android,String,Kotlin,我有一个动态生成的简单字符串: 字符串值=“一、二、三……最后” 如何以字符串值打印所有项目?很简单。您可以尝试以下方法:- for (x in "one, two, three...last".split(", ")) { println(x) } 很简单。您可以尝试以下方法:- for (x in "one, two, three...last".split(", ")) { println(x) } 您可以像这样拆分和修剪: fun main(){ val输入:String

我有一个动态生成的简单字符串:

字符串值=“一、二、三……最后”


如何以字符串值打印所有项目?

很简单。您可以尝试以下方法:-

for (x in "one, two, three...last".split(", ")) {
   println(x)
}

很简单。您可以尝试以下方法:-

for (x in "one, two, three...last".split(", ")) {
   println(x)
}

您可以像这样
拆分
修剪

fun main(){
val输入:String=“一、二、三、四、五、最后”
//用逗号分割字符串并修剪每个结果
变量结果:List=input.split(“,”).map{it.trim()}
//您可以再次以不同的分隔字符串打印列表中的项目
println(result.joinToString(separator=“;”{it->“\”${it}\”})
}
结果是

“一”;“两个”;“三”;“四”;“五”;“最后”

您可以像这样
拆分
修剪

fun main(){
val输入:String=“一、二、三、四、五、最后”
//用逗号分割字符串并修剪每个结果
变量结果:List=input.split(“,”).map{it.trim()}
//您可以再次以不同的分隔字符串打印列表中的项目
println(result.joinToString(separator=“;”{it->“\”${it}\”})
}
结果是

“一”;“两个”;“三”;“四”;“五”;“最后”
??