System Functions

STP( )

Strip Leading/Trailing Characters

Formats

1.

Strip Character from a String:

STP(string$,stp_code[,[ * | ^ ] stp_char$][,ERR=stmtref])

2.

Remove Mnemonic from a String:

STP(MNEMONIC string$[,ERR=stmtref])

3.

Remove Format from a String:

STP(string$:format$ [,ERR=stmtref])

Where:

*

Asterisk indicates a list of characters to strip.

Example:

   stp(X$,1,*" ,:")

This will strip any trailing spaces, commas, or colons from X$. A null string results in an Error #46: Length of string invalid.

^

Caret (up arrow) indicates a list of characters to not strip.

Example:

   stp(X$,3,^"0123456789.")

This will strip any character other than the digit 0 - 9 or decimal point. A null string results in an Error #46: Length of string invalid.

(The ability to specify non-stripped characters was added in PxPlus v10.00.)

stp_char$

Characters to be stripped from string. If omitted, blanks are stripped.

Example:

   stp(PTR$,3,$1B$) ! Strips out all escape characters
   stp("Hello there",3,"e") ! Strips out every occurrence of lowercase "e"

stp_code

Strip code - either string or numeric value that defines the type of strip logic to be applied.

Numeric

String

Type of Stripping to Perform

0

"L"

Strip leading

1

"R"

Strip trailing (Default)

2

"B"

Strip both leading and trailing

3

"A"

Strip all occurrences

stmtref

Program line number or statement label to which to transfer control in case of an error.

string$

String expression to be processed.

format$

Format mask to be stripped out of the string.

Returns

Stripped character string.

Description

The STP( ) function returns a character string generated by stripping specified instances of a character or a mnemonic from a string expression.

Format 1

Strip Character from a String

STP(string$,stp_code[,stp_char$][,ERR=stmtref])

This format strips the character stp_char$ (spaces if omitted) from a string expression. Depending on the stp_code value, the data can be stripped from the beginning of the string$, the end of the string$, or from both the beginning and end.

STP( ) can also be used to strip all occurrences of stp_char$ within the string.

The system returns an Error #41: Invalid integer encountered (range error or non-integer) if the value you use in stp_code is not in the range 0 to 3.

Given A$ = "    This is a test    "

STP Function

Returns

stp(A$,0) or
stp(A$,"L")

"This is a test    "

stp(A$,1) or
stp(A$,"R")

"    This is a test"

stp(A$,2) or
stp(A$,"B")

"This is a test"

stp(A$,3) or
stp(A$,"A")

"Thisisatest"

Example:

The following code sample illustrates stripping of left, right, both and all, as well as the use of "*" to indicate a list of characters:

! ^100 - STP function
     Orig$="...Test...String...",Char$="."
     print 'LF',"Original String: "+@(21)+'BR'+Orig$+'ER'+'LF'
     Strip=0,Strip$="L";
     gosub StripIt;
     print
     Strip=1,Strip$="R";
     gosub StripIt;
     print
     Strip=2,Strip$="B";
     gosub StripIt;
     print
     Strip=3,Strip$="A";
     gosub StripIt
!
! ^100 - Strip multiple characters
     Orig$="xxx Test.zzz String yyy"
     print 'LF',"Original String: "+@(25)+'BR'+Orig$+'ER'
!
     Char$="xyz.",Strip=3,Strip$="A"
     print "STP(Orig$,"+quo+Strip$+quo+",*"+quo+Char$+quo+") = ",
     print 'BR'+stp(Orig$,Strip$,*Char$)+'ER'
!
     Orig$="(888)975-7587x107"
     print 'LF',"Original String: "+@(25)+'BR'+Orig$+'ER'
!
     char$="0123456789",strip=3,strip$="A"
     print "STP(Orig$,"+quo+Strip$+quo+",^"+quo+Char$+quo+") = ",
     print 'BR'+stp(Orig$,Strip$,^Char$)+'ER'
!
     stop
!
! ^100
StripIt:
     print "STP(Orig$,"+pad(str(Strip),3,2)+","+quo+Char$+quo+") = ",
     print @(21)+'BR'+stp(Orig$,Strip,Char$)+'ER'
     print "STP(Orig$,"+quo+Strip$+quo+","+quo+Char$+quo+") = ",
     print @(21)+'BR'+stp(Orig$,Strip$,Char$)+'ER'
     return

Format 2

Remove Mnemonic from a String

STP(MNEMONIC string$[,ERR=stmtref])

This format removes all mnemonics contained within the string$. This form of the STP function is usually used to remove mnemonics from a string that are being printed or loaded into a LIST_BOX for display where the string itself contains various escape sequences to control visual attributes.

Format 3

Remove Format from a String

STP(string$:format$ [,ERR=stmtref])

This format of the STP( ) function provides the ability to remove formatting from strings. The output of a string passed through the STR( ) function to be formatted can be passed to the STP function with the same format specification to remove the formatting information.

Example:

A$="123456789"
B$=str(A$:"00-0000-000") ! yields B$ = "12-3456-789"
C$=stp(B$:"00-0000-000") ! yields C$ = "123456789"

The STP function does not mandate that the input strictly adhere to the format; that is to say, the formatting characters are stripped only if present. This means, in the above example, if B$ was "12-3456789" (missing second dash), the system would still return "123456789". The function only strips matching formatting characters. If the formatting character is not in the input string, then it is assumed optional.

(The ability to strip based on a format was added in PxPlus v9.00.)