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 开发者_JS百科want it to remain as it is. What should I do?
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"
.
- 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
精彩评论