user1003121
user1003121

Reputation: 1219

How to replace "’"?

I have a String can’t in StringBuffer(i.e. sb).
I want to change it to cant't
But when I try

sb.replace(0, sb.length(),( (sb.toString()).replaceAll("’","'")));

it gives me o/p at cant’t.

Upvotes: 0

Views: 1175

Answers (3)

Kannan Suresh
Kannan Suresh

Reputation: 4580

sb = new StringBuffer(sb.toString().replaceAll("’", "'"));

Please try this.

Upvotes: 1

Paresh Mayani
Paresh Mayani

Reputation: 128428

You can define string with ' character inside the in Strings.xml file:

For example:

<string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>

For more info, check this Android SDK: String R

Upvotes: 0

Dmytro Danylyk
Dmytro Danylyk

Reputation: 19796

Try this sb = sb.replace(0, sb.length(),( (sb.toString()).replaceAll("’","'")));

Upvotes: 0

Related Questions