Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting MS word "curly" quotes and apostrophes

Tags:

ms-word

quotes

How do I convert the MS Word quotes and apostrophes to regular quotes and apostrophes characters in Java? What's the unicode number for these characters?

“how are you doing?”

‘howdy’

Since Stack Overflow autofixes them, here's how they appear in an editor

Curly Quotes

to

"how are you doing?"

'howdy'

like image 577
user340188 Avatar asked May 13 '10 10:05

user340188


People also ask

How do I change curly to straight apostrophe in Word?

To change straight quotes to curly quotes in Word on a PC:On the File tab, click Options. Click Proofing, and then click AutoCorrect Options. In the AutoCorrect dialog box, do the following: Click the AutoFormat As You Type tab, and under Replace as you type, select the “Straight quotes” with “smart quotes” checkbox.

How do I change curly quotes to straight quotes in Word 2010?

Click the AutoFormat As You Type tab. Under the Replace as you type section, uncheck the box next to "Straight quotes" with "smart quotes."

How do I change the style of quotation marks in Word?

Go to the Word options > Proofing > Autoformat as you type. Under Replace as you type, clear the box before straight quotes with smart quotes.

How do you change smart quotes to straight quotes in Word?

Click the AutoFormat As You Type tab, and under Replace as you type, select or clear the "Straight quotes" with “smart quotes” check box. Click the AutoFormat tab, and under Replace, select or clear the "Straight quotes" with “smart quotes” check box.


3 Answers

Going off Thomas's answer, the code is:

return text.replaceAll("[\\u2018\\u2019]", "'")
           .replaceAll("[\\u201C\\u201D]", "\"");
like image 149
dimo414 Avatar answered Oct 22 '22 09:10

dimo414


Here's a very useful link for everyone dealing with Unicode: Unicode codepoint lookup/search tool.

Searching for "quotation mark" gives

‘ (U+2018) LEFT SINGLE QUOTATION MARK
’ (U+2019) RIGHT SINGLE QUOTATION MARK
“ (U+201C) LEFT DOUBLE QUOTATION MARK
” (U+201D) RIGHT DOUBLE QUOTATION MARK

There are several other quote-like symbols that you might consider replacing.

like image 37
Thomas Avatar answered Oct 22 '22 11:10

Thomas


Thank to Nick van Esch at C# How to replace Microsoft's Smart Quotes with straight quotation marks?

Here is the code ('\u2019' is ’ in MS Word), it's useful because it covers problematic word characters.

if (buffer.IndexOf('\u2013') > -1) buffer = buffer.Replace('\u2013', '-');
if (buffer.IndexOf('\u2014') > -1) buffer = buffer.Replace('\u2014', '-');
if (buffer.IndexOf('\u2015') > -1) buffer = buffer.Replace('\u2015', '-');
if (buffer.IndexOf('\u2017') > -1) buffer = buffer.Replace('\u2017', '_');
if (buffer.IndexOf('\u2018') > -1) buffer = buffer.Replace('\u2018', '\'');
if (buffer.IndexOf('\u2019') > -1) buffer = buffer.Replace('\u2019', '\'');
if (buffer.IndexOf('\u201a') > -1) buffer = buffer.Replace('\u201a', ',');
if (buffer.IndexOf('\u201b') > -1) buffer = buffer.Replace('\u201b', '\'');
if (buffer.IndexOf('\u201c') > -1) buffer = buffer.Replace('\u201c', '\"');
if (buffer.IndexOf('\u201d') > -1) buffer = buffer.Replace('\u201d', '\"');
if (buffer.IndexOf('\u201e') > -1) buffer = buffer.Replace('\u201e', '\"');
if (buffer.IndexOf('\u2026') > -1) buffer = buffer.Replace("\u2026", "...");
if (buffer.IndexOf('\u2032') > -1) buffer = buffer.Replace('\u2032', '\'');
if (buffer.IndexOf('\u2033') > -1) buffer = buffer.Replace('\u2033', '\"');
like image 11
123iamking Avatar answered Oct 22 '22 11:10

123iamking