tags:

views:

27

answers:

1

I am working on Java. Here is my code

response = URLEncoder.encode(response, "UTF-8").replaceAll("\\+", "%20");

Problem comes when there is a ' (single quote) in the string response. It gets encoded to \'.

eg - 'Collective Dynamics of Complex Networks' comes as

\'Collective Dynamics of Complex Networks\'

I want it to remain as it is. What should I do?

+2  A: 

This may work:

String after = before.replace("\\'", "'");

This assigns to after, before with \' replaced with '.

API links

  • String replace(CharSequence target, CharSequence replacement)
    • Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The replacement proceeds from the beginning of the string to the end, for example, replacing "aa" with "b" in the string "aaa" will result in "ba" rather than "ab".
polygenelubricants