4

I observed that there is a difference between the plain single quote ' and single quote in the word document . I tried to find the ASCII values from an online ASCII value finder for both the letters. I can find the ASCII value for the first one, but I can not able find the ASCII for the later one().

Even I tried to find the ASCII value using JAVA program like:

public static void main (String[] args) throws java.lang.Exception{
    char ch='\’';
    System.out.println((int)ch);
}

The Java program also giving an error while trying like this.

So, basically what is the problem with the character?

One thing I know this symbol can produced from a MS word document by typing single quote.

The character can copied into any editor, after copying into the notepad also the symbol will be remains same. But if we type a single quote it will come as plain single quote ' only.

So, basically when we type a program in a Word document and copied to an IDE or some where else to execute it. Then it will be a problem, right? So, how to solve this problem?

What will be the solution other than replacing with '?

This problem is not specifically related to any language. It is a general problem that every one should be aware.

Notable Edit:

  public static void main (String[] args) throws java.lang.Exception{
    char ch='’';
    System.out.println((int)ch);
}

Which is giving 8217(as one of the answer suggested)

But still how to resolve the problem?

Azeez
  • 318
  • 3
  • 14
  • 1
    "The problem" being that most unicode characters cannot be represented in ASCII based character sets? Well. That will likely remain unresolved. – Felix Frank Jun 13 '14 at 12:15
  • You can represent U+2019 _RIGHT SINGLE QUOTATION MARK_ in Java ASCII sources using the Unicode escape `\u2019`. – McDowell Jun 13 '14 at 12:31

1 Answers1

4

The other answers have correctly pointed out that your apostrophe is not an ASCII character but a Unicode one, called RIGHT SINGLE QUOTATION MARK.

The problem with having this character in source code is your lexer/compiler does not recognise this character as the beginning or end of a string or whatever else an apostrophe is used for in your language. So, it will not act like a normal apostrophe in your source.

You've already said you don't want to do a find and replace, so what you can do instead is make your text editor only use normal ASCII apostrophes.

If you're using Microsoft Word (which, I might add, is not a very good code editor) then you can disable "smart quotes" to get around this. There are instructions for how to do this in Word 2007 onwards and Word 2003. I've tested this and it does indeed make Word only use straight apostrophes.

Alternatively, you could also use a font that doesn't contain a RIGHT SINGLE QUOTATION MARK glyph (if you can find one).

simonwo
  • 3,171
  • 2
  • 19
  • 28