Search code examples
stringdouble-quotes

What is the difference in usage of the two alternate forms of quotation marks?


This may be a typesetting question more than a programming one, but maybe some English major-turned-programmer has the answer.

Sometimes when I copy/paste code from a source, quotation marks copy in a format that doesn't match the rest of the document.

My initial thought would be that it is just a aesthetic symbol, like a bullet point.

You can see the difference in quotes below. These were produced by typing and then copy/pasting from the indicated program. Each program handles it differently, sometimes formatting the double quotes into two separate symbols.

“hello typed into word. Notice the special quotes”

"hello typed into notepad"

My questions are:

should these affect a program's ability to find the beginning and end of a string? Checking with C#, it seems this works:

string formattedQuotes = "I said, “hello” ";
string escapedQuotes = "I said, \"hello\" ";

should I use the stylized quotes in a string instead of the default quote symbol produced in a code editor?

Do these symbols have a special name or special purpose? i.e. one for inch markings and one for quotes and one for strings.


Solution

  • The character is U+0022 QUOTATION MARK, also commonly called “double quote” (because it contains two marks). This character is also part of ASCII with the same encoding (0x22, decimal 34). Many programming languages, and certainly all of the most popular ones like C#, Java, JavaScript, C, C++, Swift, Python, Ruby, and PHP (and many more) use this character at the start and end of string literals.

    The character is U+201C LEFT DOUBLE QUOTATION MARK, and the character is U+201D RIGHT DOUBLE QUOTATION MARK. These characters are not part of ASCII. I don’t know of any languages that use these characters to delimit string literals. However, many ‘modern’ languages like C#, Java, JavaScript, Swift, and Python 3 (and probably many more) allow the use of almost any Unicode character inside a string literal. If you want to use the ‘fancy’ quotes in your strings (or in your comments), it’s probably fine.

    As for why you may be copying the fancy quotes from a document that you think contains simple quotes, I can’t say. You didn’t explain what programs have this effect, and it would almost certainly be off-topic for Stack Overflow anyway.

    Unicode also has , which is U+2033 DOUBLE PRIME and has the comment “seconds, inches”. I would recommend using that for your inch symbol, if such a recommendation weren’t off-topic. 😅