WMLScript » String » String.removeAt

Syntax:
String.removeAt(string, index, separator)
string
The mandatory string parameter can be any string containing one or more of any combination of characters and white spaces.
index
The mandatory index parameter is the position of the element in the string array. A negative index number will cause the first element to be removed and will not generate an error. An index number larger than the actual number of elements will cause the last element to be removed and will not generate an error.
separator
The mandatory separator parameter can be any character or white space that you wish to use to divide the string into substrings called elements. This parameter can also be an empty string.

Remove a specified substring from a string.

The String.removeAt function takes the given string, removes the element at the given index, removes the given separator, 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.

You can insert new elements using the String.insertAt function.

Examples

Code:
<?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>
   removeAt example
   </p>
   <do type="accept">
      <go href="RemoveAtExample.wmls#findremoveat()" />
   </do>
</card>

<card id="card2">
<p>
   string = $(oldstring)
   <br />
   index = $(index)
   <br />
   separator = $(separator)
   <br />
   new string = $(newstring)
</p>
</card>

</wml>
Explanation:

Code for RemoveAtExample.wml

Language(s): WML
Code:
extern function findremoveat()
{
   var oldstr = Dialogs.prompt("Enter a string", "Hello wireless world!");
   var indx = Dialogs.prompt("Enter an index", "1");
   var sep = Dialogs.prompt("Enter a separator", " ");
   var newstr = String.removeAt(oldstr, indx, sep);
   WMLBrowser.setVar("oldstring", oldstr);
   WMLBrowser.setVar("index", indx);
   WMLBrowser.setVar("separator", sep);
   WMLBrowser.setVar("newstring", newstr);
   WMLBrowser.go("InsertAtExample.wml#card2");
};
Explanation:

Code for RemoveAtExample.wmls

Language(s): WML

See Also: