Name
replaceAt — Replace an element in a list that is stored as a string
Usage
String.replaceAt(str
,new
,index
,sep)
: Stringstr
: Stringnew
: Numberindex
: Stringsep
Description
(See elementAt( )
’s description for an
explanation of how a string is processed as a list of
“elements.”)
Starting with the list stored as string str
,
returns a list in which the element at position
index
is replaced by the element
new
. (The first element has index zero.)
The return value is a new string; str
itself remains unmodified.
If index
is less than zero, the first
element is replaced. Similarly, if index
is past the end of the list, the last element is replaced. Note that
an empty str
is a valid list with only one
element: the empty string.
Returns invalid
if any of the values can’t
be converted to the correct types or if
sep
is the empty string.
Examples
String.replaceAt("a;b;c;d", "xxx", 1, ";")
returns string "a;xxx;c;d"
String.replaceAt("a;b;c;d", "xxx", -1, ";")
returns string "xxx;b;c;d"
String.replaceAt("a;b;c;d", "xxx", 9.8, ";")
returns string "a;b;c;xxx"
String.replaceAt("", "xxx", 0, ";")
returns string "xxx"
String.replaceAt(invalid, "x", 1, "x")
returns invalid
String.replaceAt("foo", invalid, 1, "x")
returns invalid
String.replaceAt("foo", "x", "one", "x")
returns invalid
String.replaceAt("foo", "x", 1, invalid)
returns invalid
String.replaceAt("foo", "x", 1, "")
returns invalid
Get Learning WML, and WMLScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.