STP( ) |
Strip Leading/Trailing Characters |
1. |
STP(string$,stp_code[,[ * | ^ ] stp_char$][,ERR=stmtref]) | |
2. |
STP(MNEMONIC string$[,ERR=stmtref]) | |
3. |
STP(string$:format$ [,ERR=stmtref]) |
* |
Asterisk indicates a list of characters to strip. | |||||||||||||||
Caret (up arrow) indicates a list of characters to not strip. (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. | |||||||||||||||
stp_code |
Strip code - either string or numeric value that defines the type of strip logic to be applied.
| |||||||||||||||
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. |
Stripped character string.
The STP( ) function returns a character string generated by stripping specified instances of a character or a mnemonic from a string expression.
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 |
"This is a test " |
stp(A$,1) or |
" This is a test" |
stp(A$,2) or |
"This is a test" |
stp(A$,3) or |
"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;
Strip=1,Strip$="R";
gosub StripIt;
Strip=2,Strip$="B";
gosub StripIt;
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
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.
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.)