strip/4—remove specified characters from specified parts of a string


The strip/4 function removes specified characters from specified parts of a string. The general syntax for this function is as follows:

$NEWSTR=strip($STR,$POS,$CHARS)

strip/4 arguments

Argument

Mode

Type

Description

$STR

Input

STRING

Specifies the base string from which specified characters are to be removed

$POS

Input

INTEGER

Specifies the part(s) of the string from which specified characters are to be removed

$CHARS

Input

STRING

Specifies the characters to be removed

$NEWSTR

Output

STRING

Resulting string after the specified characters have been removed

Use the strip/4 function to make a copy of the string $STR in another string $NEWSTR with all characters from $CHARS stripped off from position $POS.

The value of $POS determines the part or parts of the base string where the blank spaces are to be removed. Only the three least significant bits are considered, as shown:

Possible values for the $POS argument

$POS value

Binary value

Impacted part of the string

0

000

None

1

001

End

2

010

Middle

3

011

Middle and end

4

100

Beginning

5

101

Beginning and end

6

110

Beginning and middle

7

111

Beginning, middle, and end (entire string)

A character of the base string is considered to be located in the beginning of the string, if it and all characters preceding it, are in the character set $CHARS.

A character of the base string is considered to be located in the end of the string, if it and all characters following it, are in the character set $CHARS.

A character of the base string is considered to be located in the middle of the string, if it is in the character set $CHARS and if it is neither in the beginning nor in the end of the string.

For example, a string contains the following characters:

# !!# #a bc #! d # e #!#

The first character in the string up to, but not including, a is considered to be the beginning of the string.

The part of the string starting from the space after the e through the last character in the string is considered to be the end of the string.

The part of the string from the a through the e is considered to be the middle of the string.

strip/4 example

$MSG = strip($E.msg,6,' #!');

The variable $MSG gets the contents of the msg slot of the event with all blank spaces, # and ! characters removed, except at the end of the string. Any trailing sequence of those three characters at the end of the slot value are retained.

If $E.msg has the value from this example, $MSG will get the value abcde #!#.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*