Pluralize an Answer

From HotDocs Wiki

Jump to: navigation, search

Sometimes, you may want to pluralize a user's answer. For example, if your template asks for a job title and the user enters manager, a computation can add an s to the end of the word when it is used in a sentence such as "Along with the other managers, you will receive three weeks paid vacation."

The following computation uses a LAST expression to check if the last letter in the answer is a specific letter. Depending on what letter HotDocs finds, the computation appends s or es to the end of the answer. If the answer ends in a y, and the y is not preceded by a vowel, the y is replaced with ies.

Example

"" 
IF LAST( Text Var, 1 ) = "s" OR LAST( Text Var, 1 ) = "z" 
  Text Var + "es" 
ELSE IF LAST( Text Var, 1 ) = "y" AND NOT( "aeiou" CONTAINS MID( Text Var, LENGTH( Text Var ) - 1, 1 ) ) 
  FIRST( Text Var, LENGTH( Text Var ) - 1 ) + "ies" 
ELSE
  Text Var + "s" 
END IF

CAUTION: This computation does not take into consideration words that are already plural, or words that end in x or any other letter that would cause yet a different result. In fact, the computation does not always produce correct results even with the three letters it already evaluates. When you consider the context in which the computation is used in your template, you may be able to further refine it to work by anticipating answers a user is likely to enter.
Text Var Any Text variable containing a word to pluralize.