5. WMLScript Lang Standard Library Quick Reference

WMLScript's Lang standard library provides functions related to the WMLScript language core. It contains functions for generating random numbers, performing some arithmetic operations and dealing with data type conversion.



WMLScript Quick Reference: Functions in the Lang Standard Library

abort(message)

Ends the execution of WMLScript, and returns message and control to the WML browser. It is used for abnormal exit.

Example:

Lang.abort("Error code 110");

abs(numeric_value)

Calculates the absolute value of numeric_value.

Example:

var x = Lang.abs(-10.44);
var y = Lang.abs(-10);

x has the floating-point value 10.44.
y has the integral value 10.

characterSet()

Returns a MIBEnum value from IANA that represents the character set supported by the WMLScript interpreter. The MIBEnum value of character sets can be found at http://www.iana.org/assignments/character-sets.

exit(value)

Ends the execution of WMLScript, and returns value and control to the WML browser. It is used for normal exit.

Example:

Lang.exit(0);

Lang.exit("OK");

float()

Returns a Boolean value that tells whether floating-point numbers are supported.

isFloat(string)

Returns a Boolean value that tells whether the conversion of string into a floating-point number is possible.

Example:

var toFloatOK1 = Lang.isFloat("23.21");
var toFloatOK2 = Lang.isFloat("WMLScript Reference");

toFloatOK1 has the Boolean value true.
toFloatOK2 has the Boolean value false.

isInt(string)

Returns a Boolean value that tells whether conversion of string into an integer is possible.

Example:

var toIntegerOK1 = Lang.isInt("22");
var toIntegerOK2 = Lang.isInt("WMLScript Reference");

toIntegerOK1 has the Boolean value true.
toIntegerOK2 has the Boolean value false.

max(numeric_value1, numeric_value2)

Returns numeric_value2 if numeric_value2 is greater than numeric_value1. Otherwise returns numeric_value1.

Example:

var larger_number1 = Lang.max(10.5, 100);
var larger_number2 = Lang.max(10.5, 5.23);

Example:

larger_number1 has the integral value 100.
larger_number2 has the floating-point value 10.5.

maxInt()

Returns the largest integer that can be represented, which should be 2147483647.

min(numeric_value1, numeric_value2)

Returns numeric_value2 if numeric_value2 is smaller than numeric_value1. Otherwise returns numeric_value1.

Example:

var smaller_number1 = Lang.min(10, 100.5);
var smaller_number2 = Lang.min(10.5, 5.23);

Example:

smaller_number1 has the integral value 10.
smaller_number2 has the floating-point value 5.23.

minInt()

Returns the smallest integer that can be represented, which should be -2147483648.

parseFloat(string)

Converts string to a floating-point number.

Example:

var float_number1 = Lang.parseFloat("1.22");
var float_number2 = Lang.parseFloat("WMLScript Reference");

float_number1 has the floating-point value 1.22.
float_number2 has the value invalid.

parseInt(string)

Converts string to an integer.

Example:

var integer1 = Lang.parseInt("2334");
var integer2 = Lang.parseInt("WMLScript Reference");

integer1 has the integral value 2334.

integer2 has the value invalid.

random(numeric_value)

Returns a random integer in the range 0 to numeric_value.

Example:

var random_number = Lang.random(2);

random_number has an integral value 0, 1 or 2.

seed(numeric_value)

If numeric_value < 0, the value used to initialize the random number generator will be determined by the mobile device randomly, otherwise numeric_value is used to initialize the random number generator.

Example:

Lang.seed(-1);



Previous Page Page 5 of 6 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.

A button for going back to the top of this page