-5

I have a String which contains characters in the sequence : ":"

Instead of that, I just need: :

Like this: Original:

"Value**":"**One"

Chages I need:

"Value : One" 

What operation I should do on String like replaceAll to get the required output?

Deva
  • 1,039
  • 1
  • 14
  • 40
  • 2
    Looks like broken JSON. Better fix input at the sender. – Fildor Sep 20 '17 at 12:28
  • 1
    @Fildor I thought too but it would still requires `: {` not `{` – AxelH Sep 20 '17 at 12:28
  • @AxelH It's just a suspicion on my behalf. There is not enough info to really tell where the exact problem is and how to deal with it, IMHO. – Fildor Sep 20 '17 at 12:30
  • Ya,one of the String contains same sequence and that's now solved because of answer below.Thanks. – Deva Sep 20 '17 at 12:40
  • Possible duplicate of [How to enter quotes in a Java string?](https://stackoverflow.com/questions/3559063/how-to-enter-quotes-in-a-java-string) – Bernhard Barker Sep 20 '17 at 12:53

1 Answers1

4

You have to escape " in order to remove them

yourString = yourString.replaceAll("{\"\":", "");

EDIT

After you asked another question using this one, you should do, assuming you want to replace **":"* * (whitespace between * is for avoid bold font)

yourString = yourString.replaceAll("**\":\"**", ":");
Aldeguer
  • 821
  • 9
  • 32
  • 5
    1) `replace` is enough, your are replacing a fixed string, 2) it is advisable to use `yourString = yourString.replace(...)` to point out the fact that strings are immutable in Java. – Wiktor Stribiżew Sep 20 '17 at 12:28
  • 2
    Since the string in question looks like bad JSON, I would suggest to fix the issue where it happens: At the sender. – Fildor Sep 20 '17 at 12:29
  • 1
    As the character sequence in the question is changed now, the accepted answer is doing totally different. – Procrastinator Sep 20 '17 at 13:11
  • @procrastinator already edited, thanks for the notice – Aldeguer Sep 20 '17 at 14:19