0

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

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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))

1 Comment

That doesn't do what the OP stated (it leaves an extra separator at the start of the second string)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.