Skip to content

Modern String Replace

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › String Library › String Library › Replace

Replace

Replaces every occurrence of the text with other text.

Syntax

Replace( s, match, with_ [, ic] )

Notes

  • O(n*m)

Examples

#import "std/strings"
using strings

print Replace( "Hello World", "World", "Earth" )    '' Hello Earth
print Replace( "hello world", "WORLD", "Earth", true )    '' hello Earth

'' Single pass: a replacement containing the pattern never cascades
print Replace( "a", "a", "aa" )        '' aa, not a hang
print Replace( "abc", "", "-" )        '' abc -- an empty match copies through

Library: String Library
Category: String Library
Documented under: The Functions

Clone this wiki locally