Replace$

String management function.

The Replace$ function finds and replaces some or all occurrences of a substring within the specified string.

Usage

Same usage as the Replace option in an Edit menu.

Syntax

var$=Replace$(<string>,<search_string>,<replacing_string> [,<number_of_occurrences> [<start_position>,<end_position>]])

Parameters

<string>, string in which to find and replace

<search_string>, string to search for within <string>

<replacing_string>, string replacing <search_string> when this substring is found

<number_of_occurrences>, numeric, optional parameter to specify how many times the find/replace must be done. If this parameter is omitted or is at 0, the find/replace is done on all the occurrences.

<start_position>, numeric, optional parameter. If specified, the find/replace is done starting at the <start_position> character of <string>.

<end_position>, numeric, optional parameter. If specified, the find/replace is done starting at the <start_position> character of <string> and ending at <end_position> character of <string>.

Return value

var$, string with the replaced substrings.

Remarks

The find/replace is case sensitive.

Examples

 

a$="Hello WinTask, Hellobis"

var$=replace$(a$,"Hello","Hi")

msgbox(var$) ' displays Hi WinTask, Hibis

 

a$="Hello WinTask, Hellobis"

var$=replace$(a$,"Hello","Hi",1)

msgbox(var$) ' displays Hi WinTask, Hellobis

 

a$="Hello WinTask, Hellobis"

var$=replace$(a$,"Hello","Hi",0,2,8)

msgbox(var$) ' displays Hello WinTask, Hellobis - no changes as the Hello word is not found between the 2nd and 8th character.