How to replace Microsoft Word smart quotes with straight quotes in application text areas
You have a text area in your application. When you copy text that contains single or double quotation marks from Microsoft Word to the application's text area, the PRPC engine converts these characters to question mark characters (?).
This occurs when the Microsoft Word source document has smart quotes enabled. Compilers and interpreters, including the PRPC engine, cannot interpret smart (curly)quotation marks, but are able to interpret straight quotation marks.
To resolve this problem, create a new Edit-Input rule and associate it with the text area to replace Microsoft Word smart quotes with straight quotes, both for single and double quotation marks.
Prerequisite condition: In Microsoft Word, the default setting for ProofingAutoCorrect is to replace straight quotes with smart quotes as you type text in Word. Check this default setting, which you should keep for formatting text when authoring content:
- On the
menu, click .
- In the Word Options window, click .
- Click the AutoFormat As You Type tab to see the list of elements to Replace As You Type.
- Verify that the check box "Straight quotes” with “smart quotes” is selected.
Next, follow these steps to see the problem:
- From your Microsoft Word document, copy the sentence “This is a “Susan-Test”.” into the text area of your application. This string contains smart quotes:
Submit the application work form and use the Tracer to check the value of the Note text on the work page.
Notice that the smart quotation marks are converted to question marks because the PRPC engine, like all compilers, cannot interpret smart quotation marks.
Create a new EDIT INPUT rule to replace Microsoft Word smart quotes (single or double) with straight quotes, which the PRPC engine can interpret.
Continuing with the example, the following procedure shows you how to create the rule EDIT INPUT FixSmartQuotes. In this example, the rule converts the opening and closing double smart quotes from Microsoft Word to straight quotes.
You can add additional lines of Java code to fix other smart characters as needed, for example, single quotation marks.
- Create a new EDIT INPUT rule named FixSmartQuotes and code the Java Source as shown in the following snippet and screen.
The first line of code replaces the opening double smart quotation mark with a straight quotation mark.
The second line of code replaces the closing double smart quotation mark with a straight quotation mark.
theValue = theValue.replace ("“", "\"");<br />
theValue = theValue.replace ("”", "\"");
- In the Property Work-pyNote, the Advanced tab, specify the call to the EDIT-INPUT FixSmartQuotes rule so that the automatic conversion occurs any time that smart double quotes from Microsoft Word are inserted into the pyNote property through the PRPC application user interface.
- Run the Tracer to see how the rule EDIT INPUT FixSmartQuotes replaces the double smart quotes copied in from Microsoft Word with double straight quotes.
In this example, the properties for the TraceEvent for pyWorkPage show the correct text: Straight quotation marks now appear in the text as expected instead of question marks.
Smart quotes: The hidden scourge of text meant for computer consumption
Published February 6, 2015 — Updated October 2, 2015