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 |
- 1. WMLScript Introduction
- 2. Hello World WMLScript Example
- 3. Compiling WMLScript Code
- 4. WMLScript Language Rules
- 5. Defining WMLScript Functions
- 6. Calling WMLScript Functions
- 7. WMLScript Variables
- 8. WMLScript Data Types
- 9. WMLScript Variables Vs WML Variables
- 10. Passing Arguments to Functions By Value and By Reference
- 11. WMLScript Operators
- 12. WMLScript Conditional Statements
- 13. WMLScript Looping Statements
- 14. WMLScript Standard Libraries Overview
- 15. WMLScript WMLBrowser Standard Library
- 16. WMLScript Dialogs Standard Library
- 17. WMLScript String Standard Library
- 18. WMLScript Float Standard Library
- 19. WMLScript Lang Standard Library
- 20. WMLScript URL Standard Library
- 21. WMLScript Example: Validating Form Data