The HotDocs Computation Archive
Get Extra Help

0020 - Remove Spaces

Description:

Remove spaces from a string or text variable.


• Code •

""

// Turn off ASKing
ASK NONE

// Set up a loop: One cycle for each character in the text variable
SET loopLimit-n[ LENGTH( TextVar ) ] TO 1

// Perform the loop: Each pass examines one character
REPEAT Loop

   // Is this a space?
   SET char TO MID( TextVar, COUNTER, 1 )
   IF char != " "

      // No ... so keep it
      RESULT + char

   END IF

   // Reset the loop
   SET loopLimit-n TO UNANSWERED

END REPEAT
ASK DEFAULT

• Explanation •

This computation will remove all whitespace from a text variable or string. (Whitespace is a tab, return or space). So the string "X VJ7-002 z" will become "XVJ7-002z".

The computation uses the loop described in Computation #0015: Loops Via Repeat to go through the string in TextVar character-by-character, and appends to the RESULT only those characters that are not whitespace.

See also, Computation #0068: Strip Punctuation, Computation #0130: Multi-line to Single-line, and Computation #0141: Clean Up Spaces.

 

• Model Template •

This template has everything you need set up and configured for you. It will work as-is, or can be adapted to your variable and dialog names. It contains: 1) sample Word and WordPerfect templates (or an Automator form) to demonstrate an implementation of the computation, 2) a component file containing the computation and all supporting dialogs and variables, and 3) instructions for adapting the computation for your use.

(Go to the download page)

 
 

• Contributors •

LegalCS