0

I have variable like this:

val data = "'1','a','13','100','b'"

and I want to replace the variable became to

val data = "1,'a',13,100,'b'"

If variable has a integer character, its will be remove the quotes (''). How can I do it?

4
  • Where is the List in this code? Commented Apr 20, 2020 at 9:39
  • if I have list like this. val list = List(1,13,100) -> this is a list of integer.. and then can I replace val data based on list value above? Commented Apr 20, 2020 at 9:40
  • I don't know how it relates to this question. Where did the strings go? Scala is a strictly typed language, you can not have both strings and integers in the same list. Do you want to remove the strings from the list? Can you update your question with a proper input/output example? Commented Apr 20, 2020 at 9:43
  • I want to remove the quotes if the value is in list - > val list = List(1,13,100) from val data = "'1','a','13','100','b'" to val data = "1,'a',13,100,'b'" Commented Apr 20, 2020 at 9:46

1 Answer 1

2

I think maybe this is what you want?

val data = "'1','a','13','100','b'"  //a String, not a List
val newData = "'(\\d+)'".r.replaceAllIn(data, "$1")
//newData: String = 1,'a',13,100,'b'
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.