I can't do a simple operation with String, replace \' with *.
Example: t'est\'
-> t'est*
I have tried with replace and replaceAll methods:
String s has the value: "t'est\'"
;
s.replaceAll("\'", "*"); -> result: t*est*
s.replaceAll("\\'", "*"); -> result: t*est*
s.replaceAll("\\\'", "*"); -> result: t*est*
s.replaceAll("\\\\'", "*"); -> result: t'est'
s.replace("\'", "*"); -> result: t'est'
s.replace("\\'", "*"); -> result: t'est'
s.replace("\\\'", "*"); -> result: t'est'
s.replace("\\\\'", "*"); -> result: t'est'
But I don't get the result t'est* in any case.
Are you sure of the value of s
? '
isn't a meaningful escape character, so if you write String s = "t'est\'"
, the value of s
will just be "t'est'"
. To include the additional \
character, you need to escape it by writing String s = "t'est\\'"
. Then, I think "\\\\'"
would be the regular expression to use to find it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With