Skip to content

String.Replace

boxgaming edited this page Aug 5, 2025 · 2 revisions

Returns a new string with all matches of a pattern replaced by a replacement. The pattern can be a string or a regular expression.

Syntax

result$ = String.Replace (s$, searchStr$, replaceStr$ [, regex%])

Parameters

  • The s$ parameter contains the source string.
  • The searchStr$ indicates the search pattern used to locate the values to replace in the given string s$.
  • The replaceStr$ parameter contains the replacement value.
  • If true (non-zero) the optional regex% parameter indicates that the searchStr$ parameter should be evaluated as a regular expression. By default, it will be treated as a plain string.

Example

Import String From "lib/lang/string.bas"

Dim s As String
s = "The quick brown fox jumped over the lazy dog. It barked."

s2 = String.Replace(s, "fox", "wolf")
s2 = String.Replace(s2, "dog", "coyote")
Print s2

s2 = String.Replace(s, "fox|dog", "animal", -1)
Print s2

Output

The quick brown wolf jumped over the lazy coyote. It barked.
The quick brown animal jumped over the lazy animal. It barked.

See Also

Javascript - String.replaceAll()

Clone this wiki locally