world.Replace

MUSHclient script function (Method)

Replaces one substring with another

Prototype

BSTR Replace(BSTR Source, BSTR SearchFor, BSTR ReplaceWith, boolean Multiple);

Data type meanings

Description

This is a utility function for doing a "find and replace" inside a string.

It is intended to simplify writing scripts that need to replace things.

If "Multiple" is true then all occurences are replaced, otherwise only the first one is replaced.

VBscript example

world.Note world.Replace ("go north, go east", "go", "walk", true)

Jscript example

world.Note(world.Replace("go north, go east", "go", "walk", true));

PerlScript example

$world->Note($world->Replace("go north, go east", "go", "walk", true));

Python example

world.Note(world.Replace("go north, go east", "go", "walk", True))

Lua example

Note(Replace("go north, go east", "go", "walk", true))

Lua notes

The Multiple flag is optional, and defaults to true.

Return value

The source string with one or more occurences of "SearchFor" replaced by "ReplaceWith".

Related topic

Utilities

See also

FunctionDescription
FixupEscapeSequencesConverts "escape sequences" like \t to their equivalent codes.
FixupHTMLFixes up text for writing as HTML
TrimTrims leading and trailing spaces from a string