Creates a new string by selecting a substring out of an existing string.
The
String.subString function returns a substring that is contained
in a given string. You must specify both the starting position inside
the string and the length of the substring.
This function treats a string as an array where the first index
position is numbered zero and the last index position is the total
length of the string minus one. The total length of the string can be
found using the String.length function.
You can use the String.find function to return the index
position of a specified substring in a string.
<?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>
subString
example
</p>
<do type="accept">
<go
href="SubStringExample.wmls#findsubstring()" />
</do>
</card>
<card id="card2">
<p>
string = $(strng)
<br />
start
index = $(startindx)
<br />
length = $(lngth)
<br />
substring = $(substrng)
</p>
</card>
</wml>Code for SubStringExample.wml
extern function findsubstring()
{
var str = Dialogs.prompt("Enter a string",
"");
var ind = Dialogs.prompt("Enter start
index", "");
var len =
Dialogs.prompt("Enter length", "");
var
substr = String.subString(str, ind,
len);
WMLBrowser.setVar("strng",
str);
WMLBrowser.setVar("startindx",
ind);
WMLBrowser.setVar("lngth",
len);
WMLBrowser.setVar("substrng",
substr);
WMLBrowser.go("SubStringExample.wml#card2");
};
Code for SubStringExample.wmls