The %TRIM utility removes leading and trailing whitespace (spaces and tabs) from a string. You can use the %TRIM utility in Direct Mode or include it in a source application program in the following format:

$$FUNC^%TRIM(exp)

You can also use %TRIM as a command line utility to read from STDIN and write to STDOUT in the following format:

%XCMD 'do ^%TRIM'

Utility Labels

The following labels invoke variations of %TRIM as an extrinsic function.

FUNC(s): Returns a string after removing leading and trailing whitespaces from the argument.

L(s): Returns a string after removing leading whitespaces from the argument.

R(s): Returns a string after removing trailing whitespaces from the argument.

Example:

GTM>set strToTrim=$char(9,32)_"string with spaces and tabs"_$char(32,32,32) write $length(strToTrim) 36 GTM>write "strToTrim=",?24,"""",strToTrim,"""",!,"$$L^%TRIM(strToTrim)=",?24,"""",$$L^%TRIM(strToTrim),"""",!,"$$R^%TRIM(strToTrim)=",?24,"""",$$R^%TRIM(strToTrim),"""",!,"$$FUNC^%TRIM(strToTrim)=",?24,"""",$$FUNC^%TRIM(strToTrim),""""
strToTrim= " string with spaces and tabs "
$$L^%TRIM(strToTrim)= "string with spaces and tabs "
$$R^%TRIM(strToTrim)= " string with spaces and tabs"
$$FUNC^%TRIM(strToTrim)="string with spaces and abs"

This example invokes %TRIM as an extrinsic function and demonstrates the use of its L,R, and FUNC labels.

Example:

$ echo " GT.M Rocks! " | gtm -r %XCMD 'do ^%TRIM'

GT.M Rocks!

$

This example invokes %TRIM as a command line utility which reads STDIN and writes the trimmed output to STDOUT.

loading table of contents...