trim()
Remove unwanted characters from text.
Syntax
Parameter
Parameter | Definition |
---|---|
str | string to be returned without specified characters The str can be a text string enclosed in double quotation marks, or one or more PSL commands that produce text as output. |
chars | one or more characters that are to be removed from the copy of str output by the trim() function |
behavior | optional argument that defines the behavior of the PSL trim() function The value of behavior is specified as either an integer or one of the following constants:
Default |
Description
The trim() function returns a copy of str with specified characters removed. The trim() function allows you to remove specified characters from the entire string, the beginning of the string, the end of the string, or both the beginning and end of the string. The trim() function will also remove redundant characters in the string.
Example
The following example demonstrates the trim() function by manipulating a string using all behaviors of the trim() function:
using stdpsl;
void_t main() {
string_t string, trimmed_string;
string= "LEADING\nXX\nTh$is \nlo^oks \nbet!ter \nwith \nunw*anted \n" .
"char##acters \nremo@ved..\nXX\nTRAILING";
trimmed_string = trim(string,"\n$^!*#@");
print(string,"\n");
print("\n",trimmed_string);
trimmed_string = trim(trimmed_string,"LEADING",TRIM_LEADING);
print("\n",trimmed_string);
trimmed_string = trim(trimmed_string,"TRAILING",TRIM_TRAILING);
print("\n",trimmed_string);
trimmed_string = trim(trimmed_string,"XX",TRIM_LEADING_AND_TRAILING);
print("\n",trimmed_string);
trimmed_string = trim(trimmed_string,".",TRIM_REDUNDANT);
print("\n",trimmed_string);
}
This example produces the following output:
XX
Th$is
lo^oks
bet!ter
with
unw*anted
char##acters
remo@ved..
XX
TRAILING
LEADINGXXThis looks better with unwanted characters removed..XXTRAILING
XXThis looks better with unwanted characters removed..XXTRAILING
XXThis looks better with unwanted characters removed..XX
This looks better with unwanted characters removed..
This looks better with unwanted characters removed.