1

I have an Array like this.

scala> var x=Array("a","x,y","b")
x: Array[String] = Array(a, x,y, b)

How do I change the separator comma in array to a :. And finally convert it to string like this.

String = "a:x,y:b"

My aim is to change the comma(separators only) to other separator(say,:), so that i can ignore the comma inside second element i.e, x,y. and later split the string using : as a delimiter

1 Answer 1

4

Your question is unclear, but I'll take a shot.

To go from:

val x = Array("a","x,y","b")

to

"a:x,y:b"

You can use mkString:

x.mkString(":")  
Sign up to request clarification or add additional context in comments.

Comments

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.