REPLACE$ function REPLACE statement
Purpose: The REPLACE$ function returns a string that is the MainStr$ parameter in which the Match$ substrings have been replaced by the Change$ string.
The REPLACE statement does not return a string. Instead it directly replaces Match$ with Change$ in MainStr$.
Syntax 1: SubStr$ = REPLACE$(MainStr$, Match$, Change$) Parameters:
REPLACE Match$ WITH Change$ IN MainStr$ Parameters:
|
The REPLACE command also allows full expressions and arrays as arguments.
Syntax 3: REPLACE UCASE$(A$) WITH LCASE$(B$) IN STRIM$(C$) |
Example:
SubStr$ = REPLACE$("ABCDEFG","DEF","123")
Result:
SubStr$ will equal "ABC123G"
NOTE: Replacing a character with ASCII 0 will not work. For example,
Filter$ = "Icons(*.ico)|*.ICO|All files(*.*)|*.*" REPLACE "|" WITH CHR$(0) IN Filter$
will not work.
Something like the following must be used instead.
DIM RAW p AS CHAR PTR, Filter$[40] AS CHAR Filter$ = "Icons(*.ico)|*.ICO|All files(*.*)|*.*" p=Filter WHILE *p IF *p=124 THEN *p=0 p++ WEND
BCX Console Sample Programs using REPLACE$ function.
IREPLACE$ function IREPLACE statement
IREPLACE$ and IREPLACE perform a case insensitive replacement of the Match$ substrings contained in MainStr$.
Syntax 1: SubStr$ = IREPLACE$(MainStr$, Match$, Change$) Parameters:
IREPLACE Match$ WITH Change$ IN MainStr$ Parameters:
|
The IREPLACE command also allows full expressions and arrays as arguments.
Syntax 3: IREPLACE UCASE$(A$) WITH LCASE$(B$) IN STRIM$(C$) |
Here is a simple example.
DIM A$ A$= "This is A saMpLe oF a LONG, long, LOng, loNG, rambling sentence." IREMOVE "long, " FROM A$ 'now we can remove them all IREPLACE CHR$(32,32) WITH CHR$(32) IN A$ IREPLACE "A SAMPLE OF" WITH "not" IN A$ PRINT A$ ' Result: This is not a rambling sentence.