WMLScript » String » String.removeAt

String.removeAt(string, index, separator)
The mandatory string parameter can be any string containing one or more of any combination of characters and white spaces.
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.
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.


<?xml version="1.0"?>

<card id="card1">
   removeAt example
   <do type="accept">
      <go href="RemoveAtExample.wmls#findremoveat()" />

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


Code for RemoveAtExample.wml

Language(s): WML
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);

Code for RemoveAtExample.wmls

Language(s): WML

See Also: