Home > Language Reference > String Management Functions > Replace$

Replace$

The Replace$ function replaces a specified part of a string with another string a specified number of times.

Usage

Same usage as the Replace option in an Edit menu.  

Syntax

var$=Replace$(<source_string>, <search_string>, <replace_with_string> [, <count> [,<start>,<end>]])

Parameters

<source_string>, string to be searched.

<search_string>, string, part of the string that will be replaced.

<replace_with_string>, string, replacement substring.

<count>, optional integer, number of substitutions to perform. Default is 0 which means make all possible substitutions.

<start>, optional integer, position within <source_string> where <search_string> search begins.

<end>, optional integer, position within <source_string> where <search_string> search finishes.

Return value

var$, string, result of the replacement.

Remarks

The Replace$ function is case sensitive.

See also

Asc
Chr$
Encrypt
ExtractBetween$
InStr
InStrRev
LCase$
Left$
Len
LTrim$
Mid$
Right$
RTrim$
SplitIntoArray
Str$
Trim$
UCase$
Val

Examples

a$="Hello TesTask, Hellobis"
var$=replace$(a$,"Hello","Hi")
msgbox(var$) ' displays Hi TesTask, Hibis

a$="Hello TesTask, Hellobis"
var$=replace$(a$,"Hello","Hi",1)
msgbox(var$) ' displays Hi TesTask, Hellobis

a$="Hello TesTask, Hellobis"
var$=replace$(a$,"Hello","Hi",0,2,8)
msgbox(var$) ' displays Hello TesTask, Hellobis - no changes as the Hello word is not found
'between the 2nd and 8th character.