Reg exp question

L

laredotornado

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
 
R

RedGrittyBrick

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);
}
}
 
L

laredotornado

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,
-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top