0

Using Java, I want to go through the lines of a text and replace all "" symbols with a null entity reference.

Here is a sample string

String str = "asdsadas:\"\":asdasdASD:\"\":aSdasdcsC";

Result wanted is

String resStr = "asdsadas:null:asdasdASD:null:aSdasdcsC"
7
  • 2
    It's not clear what you mean, as that isn't valid Java code to start with. Commented Sep 15, 2015 at 15:10
  • What is stopping you? Commented Sep 15, 2015 at 15:10
  • 3
    @sᴜʀᴇsʜᴀᴛᴛᴀ Nope... you need some coffee. Commented Sep 15, 2015 at 15:12
  • 2
    @Pshemo I'm escaping from you now :P Commented Sep 15, 2015 at 15:15
  • 2
    @sri - Jordi Castilla is your friend :D Commented Sep 15, 2015 at 15:31

1 Answer 1

4

First, your string is not correct. In java you need to scape QUOTES:

String str = "asdsadas:\"\":asdasdASD:\"\":aSdasdcsC";

After, you need to escape quotes also to replace them:

String resStr= str.replaceAll("\"\"","null");
System.out.println(resStr);

OUTPUT

asdsadas:null:asdasdASD:null:aSdasdcsC

OR if you need QUOTES in the output:

String str = "\"asdsadas:\"\":asdasdASD:\"\":aSdasdcsC\"";
String resStr= str.replaceAll("\"\"","null");
System.out.println(resStr);

OUTPUT

"asdsadas:null:asdasdASD:null:aSdasdcsC"
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.