replace. Replacing substrings in the string

^string.replace[table_with_substitution_settings]
^string.replace[search_string;replace_string]
   [3.4.2]

Replaces substrings in the
string using substitution settings.

Table_with_substitution_settings is an object of class table, containing two columns:

The first contains the substring to be replaced.
The second contains the substring to replace the first one.

It is not necessary to specify column names - you may call it 'from' and 'to' or simply skip naming by using
nameless table.

Example
$s[An ugly moment I'll remember!]
Original: $s<br />
$rep[^
table::create{from   to
A
n   A
ugly   magic}]
After replace^s.replace[$rep]

The code will output:

Original: An ugly moment I'll remember!
A
fter replace: A magic moment I'll remember!



Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 18.06.2012