如何從右側的分隔符分割字符串?如何從右側分隔字符串?
例如
scala> "hello there how are you?".rightSplit(" ", 1)
res0: Array[java.lang.String] = Array(hello there how are, you?)
Python有一個.rsplit()
方法這是我後我在斯卡拉:
In [1]: "hello there how are you?".rsplit(" ", 1)
Out[1]: ['hello there how are', 'you?']
'lastIndexOf'可以返回'-1'。 – huynhjl
@huynhjl在這種情況下,splitAt將首先返回一個空字符串,其次是原始字符串。 –
當你想到了一切!你是對的,它的工作原理。 – huynhjl