Caché MultiValue Basic Reference
TRIM
[Back] [Next]
   
Server:docs1
Instance:LATEST
User:UnknownUser
 
-
Go to:
Search:    

Removes leading and trailing characters from a string.
Synopsis
TRIM(string[,char[,code]])
Arguments
string The string to trim. An expression that resolves to a string.
char Optional — The character to remove from string. An expression that resolves to a single-character string. The default is to trim blank spaces and tabs.
code Optional — The type of trimming to perform, An expression that resolves to a single-character code string. The default is to trim leading, trailing, and redundant characters.
Description
The TRIM function trims the specified character from both ends of a string (leading and trailing characters). By default, it trims leading and trailing blank spaces and tabs, and replaces multiple (redundant) spaces (including tabs) with a single space. It returns the resulting trimmed string. The original input string is not changed.
The optional char argument is case sensitive. It trims the specified character until it encounters the first instance of another character. If char is set to a multi-character string, only the first character is used. If char is omitted or set to a single-character string containing a blank space (" "), blank spaces are trimmed. If char is set to the string empty string (""), string is returned unchanged.
You can use the TRIMB function to remove blank spaces from the back end of a string (trailing blanks). You can use the TRIMF function to remove blank spaces from the front end of a string (leading blanks). Use TRIMS to remove leading, trailing, and multiple embedded blank spaces from all of the elements of a dynamic array.
Trim Codes
By default, TRIM removes leading, trailing, and redundant space characters, and tabs. TRIM also removes leading, trailing and redundant space characters if you specify a code of "R" or the empty string ("").
You can perform other types of trim operation by specifying a single-character code string. The following are the available code characters:
A All occurrences of char removed from string.
B Both leading and trailing occurrences of char removed.
D Duplicate blank spaces and leading and trailing blank spaces removed. char must be specified, but its value is ignored.
E Remove trailing spaces. char must be specified, but its value is ignored.
F Remove leading spaces. char must be specified, but its value is ignored.
L Leading occurrences of char removed.
R Redundant, leading, and trailing occurrences of char removed. This is the default.
T Trailing occurrences of char removed.
These code characters are not case sensitive.
Examples
The following example uses the TRIM function to trim leading and trailing spaces:
MyVar = TRIM("  Caché  ")
        ! MyVar contains "Caché".
PRINT LEN(MyVar),"[":MyVar:"]"
The following example uses the TRIM function to trim leading and trailing lowercase “a”. In this case, leading a's are trimmed until an uppercase A is encountered and trailing a's are trimmed until a blank space is encountered:
MyVar = TRIM("aaaaaAnaconda aaaa",’a’)
        ! MyVar contains "Anaconda ".
PRINT LEN(MyVar),"[":MyVar:"]"
See Also