我有一个字符串,我想拆分它,然后删除最后一部分。
例如对于这个输入类似的东西:
var example = "Long string to split in the last space"
我想达到这个结果
var result = "Long string to split in the last"
最佳答案
使用 substringBeforeLast
:
"Long string to split in the last space".substringBeforeLast(" ")
关于Kotlin 在最后一个空格分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54619097/