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:
Return Value:
REPLACE Match$ WITH Change$ IN MainStr$ Parameters:
REPLACE UCASE$(A$) WITH LCASE$(B$) IN STRIM$(C$) Parameters:
|
Example:
DIMSubStr$ SubStr$ = REPLACE$("ABCDEFG","DEF","123")
Result:
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:
Return Value:
IREPLACE Match$ WITH Change$ IN MainStr$ Parameters:
IREPLACE UCASE$(A$) WITH LCASE$(B$) IN STRIM$(C$) Return Value:
|
Here is a simple example.
DIM A$ A$ = "This is A saMpLe oF a LONG, long, LOng, loNG, rambling sentence." IREMOVE "long, " FROM A$ 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.