17. WMLScript String Standard Library

WMLScript's String standard library provides 16 functions to help WAP developers to perform many kinds of string operations. Some of the functions are also used to simulate arrays in WMLScript.

In the following sections, we will look at some of the more commonly used functions in the String standard library. Then we will see how to simulate arrays.


17.1. Getting the Character at a Certain Index in a String: charAt() Function

The charAt() function of the String standard library can help you get the character at a certain index in a string. Like in many other programming languages, you can consider a string as an array of characters in WMLScript. The character index counts from 0. For example, the first character has the index 0, the second character has the index 1, etc. The syntax of charAt() is:


String.charAt(string, character_index);


The charAt() function returns the character at the position character_index of string. If character_index is not a valid value, charAt() returns an empty string. If other errors occur, it returns an invalid value.

Here are some WMLScript examples:


var char = String.charAt("WMLScript Tutorial", 0);

After executing the above line of script, char contains the string value W.


var char = String.charAt("WMLScript Tutorial", -1);

After executing the above line of script, char contains an empty string since the second argument is not a valid character index.


var char = String.charAt("WMLScript Tutorial", "wml");

After executing the above line of script, char contains invalid.


Previous Page Page 40 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.