The HotDocs Computation Archive
Get Extra Help

0032 - Using Quotation Marks in a String

Description:

How to place quotation marks in a text string or variable.


• Explanation •

There are three ways to use quotation marks within a quoted string: 1) Doubling the marks, 2) using paired single-quotes, or 3) with a text variable.

Doubling the marks. The first way is to place two sets of quotation marks instead of one. For example:

SET TextVar TO "He said I was a ""cool"" guy."

will produce:

He said I was a "cool" guy.

The drawback to this method is that it seems to be subject to an "anomaly" in HotDocs that occasionally wreaks havok on double quotes (see below).

Single quotes. The second method is to use two single quotes instead of double quotes. For example:

SET TextVar TO "He said I was a ''cool'' guy."

will produce:

He said I was a ''cool'' guy.

The quotes around "cool" are two single quotes rather than double quotes. The quality of this solution varies according to word processor and whether "smart quotes" are being used.

Text Computation. The third option produces quotation marks while minimizing the frustrations of the "double quote anomaly." With this method, you create a text computation variable called, simply, q. The script of q will simply be a string that creates one double quotation mark (four double quotes with no spaces):

""""

You can now reference q anywhere in a computation that you need quotation marks within a quoted string. For example:

SET TextVar TO "He said I was a «q»cool«q» guy."
SET TextVar TO "He said I was a " + q + "cool" + q + " guy."

Both will return the same result:

He said I was a "cool" guy.

Now should the "double quote anomaly" strike your template, the only place that will be affected is the computation that creates the quote value. All of your q references will remain untouched.


•  •  •  •  •  •  •

A Warning About Double Quotation Marks
(from the HotDocs ListServ)

(Note: The post below related to HotDocs 5.1. There has been no mention of the problem for subsequent versions of HotDocs, so it may have been addressed.)

Perhaps this is old news to some of you, but I was looking for a technique that allows for the result of a text computation variable to contain quotation marks, as in the following sentence:

The word "quotes" is in quotation marks.

The problem is that the text within the computation variable must itself be contained within quotation marks and HotDocs interprets the first quotation mark before the word "quotes" as the end of the result, thereby producing an "Invalid Computation Variable." For example, the following line in a computation variable would not be allowed:

RESULT + "The word "quotes" is in quotation marks."

I tried double quotes with the kind of success I would not wish on my worst enemy. I used the following line in the computation:

RESULT + "The word ""quotes"" is in quotation marks."

The "Invalid Computation Variable" message went away and the Test button produced the desired result. I then continued with programming many variables in this fashion and all was well until I renamed a variable. If ANY variable is renamed, ALL lines in ALL computations containing double quotes are altered in a predictable fashion. The double quotes are replace with single quotes and the last two characters before the final quotation mark are duplicated. Needles to say, the computation no longer produced the desired result and again became an "Invalid Computation Variable." Our example above became:

RESULT + "The word "quotes" is in quotation marks.s."

I could not find any information on this "bug," but wanted to warn others, assuming the error is as repeatable on your systems as on mine.