From: laredotornado on
Hi,

I'm using Java 1.6. How do I replace all instances of a character
whose int code resolves to 8217 with a UTF-8 apostrophe (e.g. "'")?

- Dave
From: RedGrittyBrick on
On 02/08/2010 15:02, laredotornado wrote:
> Hi,
>
> I'm using Java 1.6. How do I replace all instances of a character
> whose int code resolves to 8217 with a UTF-8 apostrophe (e.g. "'")?
>

public class ReplaceQuote {
public static void main(String[] args) {
String s = "-->\u8217<--";
System.out.println(s);
s = s.replaceAll("\u8217", "'");
System.out.println(s);
}
}


--
RGB
From: bugbear on
RedGrittyBrick wrote:
> On 02/08/2010 15:02, laredotornado wrote:
>> Hi,
>>
>> I'm using Java 1.6. How do I replace all instances of a character
>> whose int code resolves to 8217 with a UTF-8 apostrophe (e.g. "'")?
>>
>
> public class ReplaceQuote {
> public static void main(String[] args) {
> String s = "-->\u8217<--";
> System.out.println(s);
> s = s.replaceAll("\u8217", "'");
> System.out.println(s);
> }
> }
>
>

I suspect the OP was thinking of "RIGHT SINGLE QUOTATION MARK"
which is 8217 decimal, but 2019 hex.

Since the \u (in Java) is hex, we need
"\u2019" in the replacement pattern.

BugBear
From: laredotornado on
On Aug 2, 9:26 am, bugbear <bugbear(a)trim_papermule.co.uk_trim> wrote:
> RedGrittyBrick wrote:
> > On 02/08/2010 15:02, laredotornado wrote:
> >> Hi,
>
> >> I'm using Java 1.6.  How do I replace all instances of a character
> >> whose int code resolves to 8217 with a UTF-8 apostrophe (e.g. "'")?
>
> > public class ReplaceQuote {
> >     public static void main(String[] args) {
> >         String s = "-->\u8217<--";
> >         System.out.println(s);
> >         s = s.replaceAll("\u8217", "'");
> >         System.out.println(s);
> >     }
> > }
>
> I suspect the OP was thinking of "RIGHT SINGLE QUOTATION MARK"
> which is 8217 decimal, but 2019 hex.
>
> Since the \u (in Java) is hex, we need
> "\u2019" in the replacement pattern.
>
>    BugBear

Thanks, switching to 2019 (RIGHT SINGLE QUOTATION MARK) worked great,
-