These standard function libraries provide a mechanism to extend the WML script language, which must follow the rules of WML script.
Supported data formats
The following WML script format is used in the definition of the program so that it can record the format of program parameters and rotation values.
Boolean
Integer
Float
String
Invalid
In addition, if the integer and floating-point value formats are acceptable, you can use number to record the parameter format, if the format used is the supported format, you can use any to record.
Data format Conversion
The function library program has the same processing error as the WML script language.
The invalid program parameter produces a invalid return value.
The parameters of the program cannot be converted to the required parameter format, then a invalid return value is generated.
A program-related error is returned with an appropriate error code, and the value depends on how each program is defined.
6.2 Lang Function Library
Name: Lang
Description: This function library contains programs that are closely related to the core of the WML script language.
Abs
Program: ABS (Value)
Note: The absolute value of the number given by the postback.
If the given number is an integer, the integer is returned.
If the given number is a float, the floating-point numbers are returned.
Parameter: value= number.
Return value: Number or invalid.
Exceptional condition: var a =-3;
var b =lang.abs (a);//b=3
Min
Example: var a =-3
var B = Lang.abs (a);
var c = lang.min (A.B);
var d = lang.min (45, 76.3);//d=45 (Ingteger)
var e = lang.min (45, 76.3);//e=45 (Ingteger)
Max
Program: Max (value1,value2)
Note: The return value given by the two number of large value, the return value in the format and the value of the selected values and format the same, it is selected in the following way:
The integer and floating-point conversion rules in the WML script operator data format can be used to confirm the data format in order to perform the comparison action.
Parameters: value1 = number
value2 = number
Postback value: Number or invalid
Exception condition: None
Example: Var a =-3;
var b =lang.abs (a);//b=3
var c = lang.min (A.B);
var d = lang.min (45, 76.3);//d=45 (Ingteger)
var e = lang.min (45, 76.3);//e=45 (float)
parseint
Program: parseint (value)
Note: Return the integer value defined by the string value, and the valid integer syntax is defined by the WML script numeric string grammar or near-value integer, which is the following additional parsing rule:
The first character is not preceded by A +,-or decimal digit, and the interpreter ends.
Result: The parsed string is converted to an integer value.
Example: var i =lang.parseint ("1234"); i=1234
var j =lang.parseint ("M/S"); j=100
Parsefloat
Program: parsefloat (value)
Note: Return the floating-point value defined by the string value, the legal floating-point number syntax is defined by the WML script numeric string grammar or the near-value integer name, and the following are the additional parsing rules:
The first character cannot be parsed into a floating-point expression, parsing ends.
End: The parsed string rotation is replaced by a floating-point number.
Parameters: value= String
Return value: Floating-point number or invalid
Exception: Parse error returns to invalid
Example: Var a =lang.parsefloat ("123.7 Hz"); a=123.7
var b =lang.parsefloat ("7.34e2 Hz"); B=7.34e2
var c =lang.parsefloat ("70.0e-2 F"); C=70.0e-2
var d =lang.parsefloat (" -1.c"); d=0.1
var e =lang.parsefloat ("100"); e=100.0
var f =lang.parsefloat ("number:5.5"); F=invalid
var g =lang.parsefloat ("7.3e meters"); G=invalid
var h =lang.parsefloat ("7.3e-m/s"); H=invalid
Isint
Program: Isint (value)
Note: If each of the predefined value values can be converted to an integer by using parseint (value), the Ture value is returned, or false is returned.
Parameters: value= arbitrary values
Return value: Boolean value or invalid
Exception condition: None
Example: Var a=lang.inint ("-123"); Ture
var a =lang.minint ("123.33"); Ture
var a =lang.minint ("string"); False
var a =lang.minint ("#123"); False
var a =lang.minint ("invalid"); Invalid
Isfloat
Program: Isfloat (value)
Note: If each of the predefined value values can be converted to an integer by using parseint (value), the Ture value is returned, or false is returned.
Parameters: value= arbitrary values
Return value: Boolean value or invalid
Exception condition: None
Example: Var a=lang.inint ("-123"); Ture
var a =lang.minint ("123.33"); Ture
var a =lang.minint ("string"); False
var a =lang.minint ("#123"); False
var a =lang.minint ("invalid"); Invalid
Maxint
Program: Maxint ()
Description: Returns the largest integer value.
Parameters: None
Postback value: Integer 2147483647
Exception condition: None
Example: Var a =lang.minint ();
Minint
Program: Minint ()
Description: Returns the smallest integer value
Parameters: None
Postback value: integer-2147483647
Exception condition: None
Example: Var a =lang.minint ();
Float
Program: Float ()
Note: If there is support for floating-point numbers, return ture, no word returns false.
Parameters: None
Postback Value: Boolean value
Exception condition: None
Example: var floatssupported = Lang.float ();
Exit
Program: Exit (Value)
Description: Ends the interpretation of the WML script bit code and then returns to the control of the calling WML script interpreter, returning the specified value, which you can use to perform the end of the general program, and the execution of the WML script must stop.
Parameters: valre= arbitrary values
Return value: None, this program end interpretation
Exception condition: None
Example: Lang.exit ("Value:" + myval);//returns a string
Lang,exit (invalid);//Returns invalid
Abort
Program: Abort (errordescription)
Note: Abort the interpretation of the WML script bit code and return to the control of the calling WML script interpreter and back to ErrorDescription, you can use this program to perform an abnormal abort, the caller detects a serious error, and the WML script executes and interrupts.
If the errordescription format is invalid, the string invalid is used in place of errordescription.
Parameters: ErrorDescription = string
Return value: None, this program end interpretation
Exception condition: None
Example: Lang.abort ("Error:" + errval); Error Value string
Radndom
Program: Random (value)
Note: Return an integer value of a positive number, that is, to be greater than or equal to zero, but must be less than the given value, and the return value is randomly selected by near normal distribution.
Parameters: value= integers
Postback value: integer or invalid
Exception: If value equals 0, the program will return 0
If value is less than 0, the program invalid
Example: var a = 10;
var b =lang.random (5.1) *a;//b=0..50
var c = lang.random ("string"); C=invalid
Reed
Program: Seed (Alue)
Description: Initialize a random number sequence and return an empty string
If value is 0 or a positive integer, the given value is used to initialize, whereas the value that is randomly initialized is used.
If value is a floating-point number, the exact integer value is computed using Float.int () first.
Parameters: value= integers
Postback value: string or invalid]
Exception condition: None
Example: Var a =lang.reed (123);//A= ""
var b =lang.random (20); b=0..20
var c = lang.seed ("seed"); C=invalid (random seed//left unchanged)
CharacterSet
Program: CharacterSet ()
Note: Back up the word set supported by the WML script interpreter, and the postback is just an integer used to record the MIB enum value set by the IANA, which can only represent all of the word sets.
Parameters: None
Postback value: integer
Exception condition: None
Example: Var charset = Lang.characterset (); CharSet = 4 for Latinl
6.3 Float Function Library
Name: Float
Description: This function library contains typical and commonly used floating-point arithmetic programs.
Int
Program: Int (value)
Description: Return the integer portion of the given value.
Parameters: value= Digits
Postback value: integer or invalid
Exception condition: None
Example: var a = 3.14;
var b =float.in (a); B=3
var c =float.in (-2.8); C=-2
Floor
Program: Floor (value)
Note: Return the integer value, as long as the nearest given value but not greater than it.
If value is already an integer, the result is the value itself.
Parameters: value= Digits
Postback value: integer or invalid
Exception condition: None
Example: var a = 3.14;
var b =float.in (a); B=3
var c =float.in (-2.8); C=-3
Ceil
Program: Ceil (value)
Note: Return an integer value that is closest to the given value but not less than it.
If value is already an integer, the result is the value itself.
Parameters: value= Digits
Postback value: integer or invalid
Exception condition: None
Example: var a = 3.14;
var b =float.in (a); B=4
var c =float.in (-2.8); C=-2
Pow
Program: POW (x,y)
Description: Return x's Y-second square value.
If x is a negative number, then Y must be a positive number.
Parameters: x= Digits
y= Digital
Return value: Floating-point number or invlid
Exception: If x= = 0 and y<0, then the postback invalid
If X<0 and y is not an integer, return the invalid
Example: Var a =3
var b =float.pow (a,2); B=9
Round
Program: Round (value)
Description: Returns the integer nearest to the given value
If two integer values are equal to the program of value close, select a larger number.
If value is already a positive number, the result is value itself.
Parameters: value= Digits
Postback value: integer or invalid
Exception condition: None
Example: Var a=float.round (3.5);//a=4
var B=float.round (-3.5); B=-3
var c=float.round (0.5);//C=1
var d=float.round (-0.5); D=0
Squt
Program: sqrt (value)
Description: Returns the square root approximation of the value given.
Parameters: Value= Floating-point numbers
Return value: Floating-point number or invalid
Exception: If value is negative, return invlid
Example: Var a=4;
var b=float.squt (a); b=2.0
var c=float.squt (5); c=2.2360679775
Maxfloat
Program: Maxfloat ()
Description: Returns the largest floating-point value in the supported but quasi-floating-point number format of IEEE 754.
Parameters: None
Postback value: Float 3.40282347E+38
Exception condition: None
Example: Var a=float.maxfloat ();
Minfloat
Program: Minfloat ()
Description: Returns the smallest floating-point value in the supported but quasi floating-point number format of IEEE 754.
Parameters: None
Postback value: Float 1.17549435E-38
Exception condition: None
Example: Var a=float.minfloat ();
6.4 String Function Library
Name: string
Description: This library contains a collection of string programs, a string that can be an array of characters, each character has an index, the first character of the string is indexed as 0, and the length of the string is the number of characters in the array.
You can use some special dividers to define different strings, so you can access the elements that are delimited to the element index, the index value of the first element in the string is 0, and each string delimiter is separated by two elements, but the character is not used as a separator.
A space character may be one of the following characters:
Program: Length (String)
Description: Returns the length of the given string (the number of characters).
Parameters: string= String
Postback value: integer or invalid
Exception condition: None
Example: Var a= "ABC";
var b=string.length (a); B=3
var c=string.length (""); C=0
var d=string.length (342); D=3
Is Empty
Program: Is Empty (string)
Note: Returns a Boolean value TRUE if the string length is zero, and returns false on the contrary.
Parameters: string= String
Return value: Boolean value or invalid
Exception condition: None
Example: Var a= "Hello;"
var b= "";
var c=sting.isempty (a); C=false
var c=sting.isempty (b); D=ture
var c=sting.isempty (ture); E=false
CharAt
Program: CharAt (Sting.index)
Description: Return the character specified by the index value in string.
Parameters: string= Number of characters
index= number (returns the character specified by index)
Postback value: string or invalid
Exception: If the value of index exceeds the range of the string, the empty string ("") is returned.
Example: Var a= "My name is Joe"
var b=sting.charat (a,0); b= "M"
var c=sting.charat (a,100); C= ""
var d=sting.charat (34.0); D= "3"
var E=sting.charat (A, "a"); E=invalid
SubString
Program: subString (String,startindex,length)
Description: Returns a new string to replace the given string, the new string given the index value to begin with, and its length is given a long decision.
If the startindex is less than 0, the 0来 is treated as an index value.
If length is greater than the number of remaining characters, lenght will be replaced by the number of characters remaining.
If startindex to lenght is a floating-point number, the Float.int () is used first to compute the correct integer value.
Parameters: string= Number of characters
startindex= Digital
lenght= Digital
Postback value: string or invalid
Exception: If startindex is greater than the last index value, then the postback will be empty string ("")
If lenght<=0, the pass empty string ("")
Example: Var a= "ABCD";
var b=string.substring (a,1,2); b= "BC"
var c=string.substring (a,2,5); C= "CD"
var d=string.substring (1234,0,2); D= "12"
Find
Program: Find (string,substring)
Description: The index value of the first character that the string substring is looking for and the original string string matches.
If it does not match, the integer value-1 is passed.
Two character passes, if they are equal, are defined as not conforming.
Parameters: string= String
substring= string
Postback value: integer or invalid
Exception condition: None
Example: Var a= "ABCDE";
var b=string.find (A, "CD"); b=2
var c=string.find (34.2, "de"); C=-1
var d=string.find (A, "gz"); D=-1
var e=string.find (34, "3"); E=0
Replace
Program: Eplace (tring,oldsubstring,newsubstring)
Description: Passes the new string, which is replaced with the new string Newsubstring string, which is the old character Fu oldsubstring that matches the string given. If the two strings are equal, the definition is consistent.
Parameters: string= String
oldsubstring= string
newsubstring= string
Postback value: string or invalid
Exception condition: None
Example: Var a= "Hello joe.what be up Joe";
var newname= "Don";
var oldname= "Joe";
var c=string.replace (a,oldname,newname); C= "Hello don.what are up Don?"
var d=string.replace (a,oldname,newname); C= "Hello don.what are up Don?"
Element
Program: Element (String,separator)
Description: The number of elements string string that is delimited by the separator delimited symbol, the empty string ("") is a valid element, which means that the program will never return a value less than or equal to 0.
Parameters: string= String
Separator= string
Postback value: integer or invalid
Exception: If separator is an empty string, then the postback invalid
Example: Var a= "My name is Joe;" Age 50 ";
var b=string.elements (A, "");//b=6
var c=string.elements (A, ";"); /c=3
var d=string.elements ("", ";"); /d=1
var e=string.elements ("A", "");//e=1
var f=string.elements (";", ";"); /f=2
var g=string.elements (";;,;", ";,");//g=4
separator=;
ElementAt
Program: ElementAt (String,index,separator)
Description: Looks for the index element of the string, which is separated by the separator symbol separator and the corresponding element is returned.
If the index value is less than 0, the first element is returned.
If the index value is greater than the number of elements, the last element is returned.
If the string is an empty string, the empty string is returned.
If the index value is a floating-point number, you must first use Float.int () to calculate the correct index value.
Parameters: string= String
index= Digital
Separator= string
Postback value: string or invalid
Exception: If separator is an empty string, then the postback invalid
Example: Var a= "Hello joe.what be up Joe";
var b=string.elementat (a,0, ""); B= "My"
var b=string.elementat (a,14, ";"); C= ""
var b=string.elementat (a,1, ";"); D= "Age 50"
RemoveAt
Program: RemoveAt (String,index,separator)
Description: Separator The separator number that matches the index value to the element with string strings, and then return the new string.
If the index value is less than 0, the first element is returned.
If the index value is greater than the number of elements, the last element is returned.
If the string is an empty string, the empty string is returned.
If the index value is a floating-point number, you must first use Float.int () to calculate the correct index value.
Parameters: string= String
element= string
index= Digital
Separator= string
Postback value: string or invalid
Exception: If separator is an empty string, then the postback invalid
Example: Var a= "a A;" B C D ";
var s= "";
var c=string.removeat (a,1,s); b= "A B C D"
var d=string.removeat (a,0, ";"); c= "B C D"
var e=string.removeat (a,14, ";"); D= "A A"
Replaceat
Program: Replaceat (String,index,separator)
Description: The element in a particular index is substituted with the given element elements, and the new string is returned.
If the index value is less than 0, the first element is returned.
If the index value is greater than the number of elements, the last element is returned.
If the string is an empty string, the empty string is returned.
If the index value is a floating-point number, you must first use Float.int () to calculate the correct index value.
Parameters: string= String
element= string
index= Digital
Separator= string
Postback value: string or invalid
Exception: If separator is an empty string, then the postback invalid
Example: Var a= "B C;" E ";
var s= "";
var d=string.replaceat (A, "a", 0,s); b= "A C; E
var e=string.replaceat (A, "F", 5, ";"); D= "B C; F
InsertAt
Program: InsertAt (String,index,separator)
Description: Inserts element elements with the corresponding separator symbol separator into the original string, elements in a particular element
If the index value is less than 0, then 0 is used when the index value.
If the index value is greater than the number of elements, then element elements append the end of the strings string.
If the string is an empty string, a new string containing the element of the given elements is returned.
If the index value is a floating-point number, you must first use Float.int () to calculate the correct index value.
Parameters: string= String
element= string
index= Digital
Separator= string
Postback value: string or invalid
Exception: If separator is an empty string, then the postback invalid
Example: Var a= "B C;" E ";
var s= "";
var b=string.insertat (A, "a", 0,s); b= "A B C; E
var c=string.insertat (A, "X", 3,s); C= "B C; E X "
var d=string.insertat (A, "D", 1, ";"); D= "B c;d; E
var e=string.insertat (A, "F", 5, ";"); E= "B C; E F
Squeeze
Program: Squeeze (String)
Description: Reduces all contiguous spaces in string strings to one space.
Parameters: stromg= String
Postback value: string or invalid
Exception condition: None
Example: Var a= "Hello";
var b= "Bye jon.see you!";
var c=string.squeeze (a); C= "Hello"
var d=string.squeeze (b); d= "Bye jon.see you!"
Trim
Program: Trim (String)
Description: Deletes all the beginning and consecutive spaces in string strings.
Parameters: string= String
Postback value: string or invalid
Exception condition: None
Example: Var a= "Hello";
var b= "Bye jon.see you!";
var c=string.squeeze (a); C= "Hello"
var d=string.squeeze (b); d= "Bye jon.see you!"
Compare
Program: Compare (STRING,STRING2)
Description: The return value of this program will indicate that string1 and string2 are in the vocabulary, this relationship is based on the character code of the natural character set, and its return value is as follows:
If the string1 is less than string2, the transfer will be 1.
If the string1 equals string2, the transfer will be 1.
If the string1 is greater than string2, the transfer will be 1.
Parameters: string1= String
string2= string
Postback value: integer or invalid
Exception condition: None
Example: Var a= "Hello";
var b= "Hello";
var c=string.compare (a,b); C=0
var d=string.compare ("Bye", "Jon"); D=-1
var e=string.compare ("Jon", "Bye"); E=1
Tostring
Program: toString (value)
Note: Return a string that represents the value given, which is the same as the conversion of the WML script, except that the Invlaid value will return a "invalid" string.
Parameters: value= arbitrary values
Postback value: string
Exception condition: None
Example: Var a=string.tostring (12); A= "12"
var a=string.tostring (true); B= "true"
Format
Program: Format (format,value)
Description: Converts the value given to a string and provides a formatted string in accordance with the format given, which can only be in a specific format and can be placed anywhere in the string, using the leftmost format if more than one format is required. As for the other formats, there are empty strings instead, and the formats are as follows:
[Width] [. Precision]type
The width parameter is non-negative is a near-integer, which controls the minimum number of displayed characters, and if the output is less than the specified width, the left side of the string is blank until the minimum width is met, and the width parameter is never a value that is truncated. If the number of words in the output is larger than a specific width or not specified, all characters in value are displayed.
The precision parameter is a nonnegative decimal integer that must be preceded by a limit on the symbol (.), which is used to set the precision of the input value, the solution of which is related to the format given by the Parliament:
D defines the number of the minimum number of shows, if the number of digits in value exceeds the precision value, the input value will be added to the left of 0, if the number exceeds the precision value, value will not be truncated, the preset precision value is 1, If the precision value is set to 0 and the value page is converted to 0, the result will be an empty string.
f The number of decimal decimal digits, if the decimal point appears, after the decimal point should be at least one number, this value will be rounded to approximate numeric values, the preset precision is 6, If there are no digits after the precision is 0 or the decimal point (.), the decimal point is not displayed, and the number of digits after the value value is less than the precision value, and the letter 0 is added until the field is filled (for example: String.Format ("%2.3f", 1.2) will be " 1.200 ")
s to define the maximum number of characters to appear, the default is to show all the characters, when the width value is greater than the precision value, the width value can be ignored, and with the width value is different, precision can only cause floating-point values rounded or cut the input value.
The type parameter is a unique format parameter that appears after any format bar is an option, and the type character determines that the value given will be interpreted as an integer, floating-point number, or string, and the supported type parameters are as follows:
D integer: Enter the format of the value [-]DDDD, where the dddd is one or more decimal digits.
F Floating-point number: Enter the format of the value [-]DDDD.DDDD, where the dddd is one or more decimal digits, the number of digits before the decimal point is related to the size of the number, and the number of digits after the decimal point is related to the accuracy.
S string: the appearance of characters is related to accuracy.
The percent character (%) can be represented in the format string using an extra percentage character (%).
Parameters: format= String
Value= any value
Postback value: string or invalid
An exception; An invalid format will return the invalid value.
Example: Var a=45;
var b=-45;
var c= "Now";
var d=1.2345678;
var E=string.format ("e:%6d", a); E= "E:45"
var E=string.format ("%6d", b); f= "-45"
var E=string.format ("e:%6d", a); G= "0045"
var E=string.format ("%6.4d", b); H= "-0045"
var E=string.format ("Do It%s", c); I= "Do It Now"
var E=string.format ("%3f", D); j= "1.2345678"
var E=string.format ("%10.2f%%", a); K= "1.23%."
var e=string.format ("%3f%2f", a); L= "1.234567."
var E=string.format ("%.0d", 0); M= ""
var E=string.format ("%.7d", "Int"); n= "Invalid"
var E=string.format ("%s", ture); o= "Ture"
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.