Reputation: 367
input:
myString = ""FILTER=(ID=123,Description=456)""
output:
FILTER, (ID=123,Description=456)
basically divide the string into two parts How can i achieve this ?
Want something equivalent to str.partition(sep) as in python
Upvotes: 0
Views: 1214
Reputation: 2056
The span
-method could also be helpful for you
val myString = "FILTER=(ID=123,Description=456)"
//myString: String = FILTER=(ID=123,Description=456)
myString.span(_!='=')
//res9: (String, String) = (FILTER,=(ID=123,Description=456))
Upvotes: 0
Reputation: 41769
You want split
with a limit
parameter (but you don't get the separator as an element as in the Python partition
)
val myString = "FILTER=(ID=123,Description=456)"
myString.split("=", 2)
//> res0: Array[String] = Array(FILTER, (ID=123,Description=456))
It's actually a java method - see here
Upvotes: 4