Welcome to Developer's Home Sunday, April 20, 2014
Home - DevelopersHome.com

WMLScript String Standard Library


Preferences - Do not show ads

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.


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.


Page 40 of 71 Previous Page | Next Page
Contents at a Glance
Print this Web Page | | Back to Top
Custom Search

Feedback Form (Expand)

What do you think about this web page?






WMLScript Tutorial Table of Contents WMLScript Tutorial Contents at a Glance Preferences - Change Color Scheme Preferences - Do Not Show Ads Previous Page Next Page