Inserts an element and separator into a string.
The
String.insertAt function inserts the given element and separator
into the given string at the given index position and returns the
modified string.
This function treats a string
as an array composed of elements delimited by a separator that is
composed of one or more specified characters (including white space).
The first index position is numbered zero and the last index position
is the total number of the elements minus one. The total number of
elements in the string can be found by using the String.elements
function.
When the new element is inserted, it
will be delimited on each end by the separator. However, if the element
is added to the start of the string, there will be no leading
separator. If the element is added to the end of the string, there will
be no trailing separator.
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC
"-//WAPFORUM//DTD WML 1.1//EN"
"http://www.WAPforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1">
<p>
insertAt
example
</p>
<do type="accept">
<go
href="InsertAtExample.wmls#findinsertat()" />
</do>
</card>
<card id="card2">
<p>
string = $(oldstring)
<br />
element
= $(element)
<br />
index = $(index)
<br />
separator = $(separator)
<br />
new
string = $(newstring)
</p>
</card>
</wml>
Code for InsertAtExample.wml
extern function
findinsertat()
{
var oldstr =
Dialogs.prompt("Enter a string", "Hello world!");
var elem = Dialogs.prompt("Enter an element",
"wireless");
var indx =
Dialogs.prompt("Enter an index", "1");
var
sep = Dialogs.prompt("Enter a separator", " ");
var newstr = String.insertAt(oldstr, elem, indx, sep);
WMLBrowser.setVar("oldstring", oldstr);
WMLBrowser.setVar("element", elem);
WMLBrowser.setVar("index", indx);
WMLBrowser.setVar("separator", sep);
WMLBrowser.setVar("newstring", newstr);
WMLBrowser.go("InsertAtExample.wml#card2");
};
Code for InsertAtExample.wmls