-2

How can I transform the string

st = "[123, 123, 134,    90]"

into

s = "123 123 134 90"
Shah
  • 661
  • 2
  • 9
  • 19
  • Why not just replace all , [ and ] with ""... (note that if you use regex, `[` is a metacharacter and needs to be escaped with \ - but it is also an escape in java strings, so use \\\) – Patashu May 28 '13 at 11:43

2 Answers2

1

replace " " with ""

replace "," with " "

replace "[" with ""

replace "]" with ""

Oliver Watkins
  • 12,575
  • 33
  • 119
  • 225
  • yes [ with "" but i want to replace "," and "[" ,"]" so I used replaceAll(",\\]\\[","") but it didn't work so can you write the regex for me? – Shah May 28 '13 at 11:48
  • 2
    @agile you should do it like this `newString = replaceAll("\\[", "").replaceAll("\\]", "").replaceAll(","," ");` – Maroun May 28 '13 at 11:51
0

With Thanks to Maroun Maroun

String st = "[123, 123, 134, 90]"

String s = st.replaceAll("\\["," ").replaceAll("\\]"," ").replaceAll(","," ");
Shah
  • 661
  • 2
  • 9
  • 19