Remove All Spaces From an Answer

From HotDocs Wiki

Jump to: navigation, search

When a user answers a Text variable in the interview, unless the variable has a pattern attached to it, the user can type almost anything in the box. As the template developer, you may want to alter the user's answer to remove certain characters, such as spaces. For example, if a user is prompted to enter an account number, you may want to remove all spaces from the answer.

The following computation uses a WHILE loop (available in HotDocs 6.2 and later) to look at the user's answer, character by character, to see if there are spaces in the answer. If so, HotDocs modifies the answer to remove the spaces.


You can use this same script to remove any character from an answer. For example, if you want to remove all periods from an answer, replace " " with "." each time it appears in the script.


  SET  Text Var  TO  FIRST( Text Var, POSITION( Text Var, " " ) - 1 ) +  
  LAST( Text Var, LENGTH( Text Var ) - POSITION( Text Var, " " ) )  

Text Var Any Text variable.