我有一根绳子,我想把它分开,然后去掉最后一部分。
例如,类似于此输入的内容:
var example = "Long string to split in the last space"
我想要达到这个结果
var result = "Long string to split in the last"
发布于 2019-02-10 09:37:29
"Long string to split in the last space".substringBeforeLast(" ")
发布于 2019-02-10 09:46:30
substringBeforeLast的一个更详细的替代方案,用于使用dropLast删除最后一个n
单词
var example = "Long string to split in the last space"
var result = example.split(" ")
.dropLast(1)
.joinToString(" ")
println(result) // Long string to split in the last
https://stackoverflow.com/questions/54619097
复制