WML standard function library

xiaoxiao2021-03-06  94

6.1 WML Script Rules These Standard Library provides a mechanism for extending the WML Script language, which must follow the rules of WML Script.

Supported data format

The following WML Script format is used in the definition of the program, which can record the format of the program parameter and the rotation value.

Boolean

Integer

Float

String

Invalid

In addition, if the integer is acceptable to the floating point number parameter value format, you can use Number to record the parameter format. If the format is used is the supported format, you can record it with any.

Data format conversion

The function library program has an error handling method and the WML Script language.

The InvalID program parameter generates the INVALID backup value.

The parameters of the program cannot be converted to the parameter format you need, the INVALID is generated.

Errors related to the program have to return a proper error code, as for this value, you have to see how each program is defined.

6.2 LANG Library

Name: LANG

Note: The program contained in this library has a close relationship with the core of the WML Script language.

ABS

Program: ABS (Value)

Description: The absolute value of the number of times is given.

If the number given is an integer, the eradic is energized.

If the number given is the floating point number, the floating point number is returned.

Parameters: value = number.

Recycle value: number or invalid.

Exquisite status: 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)

Explanation: The larger value between the two numbers given by the return value, the value of the return value is the same as the value of the selected value, and the way it is selected is as follows:

The integer of the WML Script operator data format is used to confirm the data format in order to perform comparisons.

Parameters: Value1 = number

Value2 = number

Recital: Digital or Invalid

Exception: 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

Procedure: Parseint (Value)

Description: Recycling the integer value defined by the string value, the legal integer syntax is defined by the WML Script numerical string method or the near-value integer is defined, the following is an additional resolution method:

The first character is not started by , or ten credits, and the interpretation ends.

RESULTS: The parsed string switched integer value.

Example: var i = lang.parseint ("1234"); // i = 1234

Var j = lang.parseint ("100 m / s"); // j = 100

Parsefloat

Program: Parsefloat (Value) Description: Back to the floating point value defined by the string value, the legal floating point numerical syntax is defined by the WML Script numerical string method or the near-value integer entry, the following additional resolution:

The first character cannot parse into a floating point representation, and the parsing ends.

End: The parsed string switched to floating point numbers.

Parameters: value = string

Recycling value: floating point or invalid

Exquisite status: parsing errors return 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

Procedure: Isint (Value)

Note: If each pre-value value can use PARSEINT (Value) to turn into an integer, return the Boolean TURE, otherwise it will return false.

Parameters: value = Arbitrary Value

Return value: Boolean or invalid

Exception: 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 pre-value value can use PARSEINT (Value) to turn into an integer, return the Boolean TURE, otherwise it will return false.

Parameters: value = Arbitrary Value

Return value: Boolean or invalid

Exception: 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: The maximum integer value is transmitted.

Parameters: no

Recycle value: integer 2147483647

Exquisite status: no example: var a = lang.minint ();

minint

Program: minint ()

Description: Remove the minimum integer value

Parameters: no

Back to the value: integer - 2147483647

Exception: None

Example: var a = lang.minint ();

Float

Program: float ()

Note: If you have a voice that supports floating point numbers, the false is returned.

Parameters: no

Recycling value: Boolean

Exception: None

Example: var floatssupported = lang.float ();

exit

Program: exit (value)

Description: End the WML Script bit code then returns to the control of the WML Script Explorer, and return to the specified value value, you can use this program to perform the end of the general program, and the execution of the WML Script bit code It must be stopped.

Parameters: valre = Arbitrary Value

Back to the value: None, this program ends interpretation

Exception: None

Example: lang.exit ("Value:" myval); // Returns A String

LANG, EXIT (Invalid); // Returns Invalid

Abort

Program: Abort (ErrorDescription)

Note: The interpretation of the WML Script bit code is stopped back to the control of calling the WML Script Explorer, and returns ErrorDescription, you can use this program to perform abnormal abnormal abnormal abort, the calling programper detected a serious error, WML Script Execution and need to be interrupted.

If the ERRORDESCRIPTION is format INVALID, the string Invalid is used instead of ErrorDescription.

Parameters: ErrorDescription = String

Back to the value: None, this program ends interpretation

Exception: None

Example: lang.abort ("Error:" Errval); // Error Value String

Radndom

Program: Random (Value)

Description: Back to a positive integer value, that is, it is more than or equal to zero, but must be less than the given value value, the return value is close to the value randomly selected from the normal distribution.

Parameters: Value = integer

Return value: integer or invalid

Exquisite situation: If Value is equal to 0, the program comes into 0

If Value is less than 0, the program goes back Invalid

Example: var a = 10;

Var b = lang.random (5.1) * a; // b = 0..50

Var c = lang.random ("string"); // c = invalid

reed

Procedure: SEED (Alue)

Explanation: Initialization requires random numerical order and back to an empty string

If Value is 0 or positive integers, the value given is used to initialize, and vice versa uses the random initialization value.

If Value is a floating point, you will use float.int () to calculate the exact integer value.

Parameters: Value = integer

Back to the value: string or invalid]

Exception: 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: Go back to the word set supported by the WML Script Explorer, and the return is just a integer used to record the MIB ENUM value set by IANA, which can only represent all the word sets.

Parameters: no

Recital value: integer

Exception: None

Example: var charset = lang.characterset (); // charset = 4 for latinl

6.3 Float Library

Name: float

Description: This library contains a typical floating point arithmetic program with commonly used.

int

Program: int (value)

Description: The integer part of the return is given.

Parameters: value = number

Return value: integer or invalid

Exception: 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)

Description: Back to the integer value, this is just close to the value but cannot be greater than it.

If Value is already an integer, the result is this value itself.

Parameters: value = number

Return value: integer or invalid

Exception: 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: Back to a nickname but not less than its integer value.

If Value is already an integer, the result is this value itself.

Parameters: value = number

Return value: integer or invalid

Exception: 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: Recycling the Y times of X.

If x is negative, Y must be a positive number.

Parameters: x = number

Y = number

Recital value: floating point or inflid

Exquisite situation: If x = = 0 and Y <0, return to invalid

If x <0 and Y is not a integer, return to invalid

Example: var a = 3

Var b = float.pow (a, 2); // b = 9

Round

Procedure: Round (Value)

Description: Remove the integer of the closest value

If the two integer values ​​are equal to the VALUE close to the program, choose a relatively large number.

If Value is already a positive number, the result is Value itself.

Parameters: value = number

Return value: integer or invalid

Exception: None

Example: var A = float.Round (3.5); // a = 4VAR 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)

Note: The square root of value Value is passed back.

Parameters: Value = Floating point number

Recycling value: floating point or invalid

Exquisite situation: If the value is negative, return to Invlid

Example: var A = 4;

Var b = float.squt (a); //b=2.0

Var c = float.squt (5); //c=2.2360679775

Maxfloat

Program: maxfloat ()

Note: Remove the maximum floating point value in the IEEE 754 supported by IEEE 754.

Parameters: no

Back to the value: floating point 3.40282347E 38

Exception: None

Example: var a = float.maxfloat ();

Minfloat

Program: minfloat ()

Note: The minimum floating point value is transmitted back to the IEEE 754 supported by the quasi-floating point.

Parameters: no

Recycle value: floating point number 1.17549435E-38

Exception: None

Example: var a = float.minfloat ();

6.4 String Library

Name: String

Description: This library contains a collection of string programs, a string can be an array of characters, each character has an index, the first word floating index of the string is 0, the length of the string is a character in array Number of people.

You can use some special separation symbols to define different strings so you can access the elements that have been determined by the separated symbols to the element index, the index value of the first element in the string is 0, each character. The string separator is separated from two elements, but the characters cannot be used to do separate symbols.

A space of the character may be one of the following characters:

Tab: horizontal jumping position (Horizontal Tabulation)

VT: ErtiVal Tabulation

FF: FROM feed

SP: Space (SPACE)

LF: Jumping (LINE FEED)

CR: CARRIAGE RETURN

Length

Procedure: Length (String)

Description: The length of the source (the number of characters) is passed.

Parameters: String = String

Return value: integer or invalid

Exception: 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

Procedure: Is Empty (String)

Note: If the string length is zero, it is back to the Boolean TRUE, and vice versa back False.

Parameters: String = String

Return value: Boolean or invalid

Exception: None

Example: var a = "Hello;

VAR B = "";

VAR C = STINISEMPTY (A); // c = FALSE

Var c = sting.isempty (b); // d = Ture

VAR C = STINISEMPTY (TURE); // E = FALSE

Charat

Program: charat (sting.index)

Description: Retrieve the characters specified in the String in the string.

Parameters: String = number of characters

INDEX = number (recurrent character specified by INDEX)

Back to the value: string or invalid

Exception: If the value of Index exceeds the range of the string, go back to the empty string ("")

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, "first"); // E = invalid

Substring

Program: Substring (String, StartIndex, Length)

Note: Remove a new string to replace the given string, the index value given by this new string begins, and its length is given the LENGTH decision.

If StartIndex is less than 0, 0 will be used as a index value.

If Length is greater than the number of remaining characters, the Lenet will be replaced by the remaining characters.

If StartIndex is a floating point number, you will use float.int () to calculate the correct integer value.

Parameters: String = number of characters

STARTINDEX = number

Lenet = number

Back to the value: string or invalid

Exception: If StartIndex is greater than the final index value, return the empty string ("")

If Lenght <= 0, a spacious 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)

Note: The index value of the string subString and the original string String match the string Substring and the original string string.

If you do not match, pass the integer value -1.

If the two characters are equal, it is defined as unquirmed.

Parameters: String = String

Substring = string

Return value: integer or invalid

Exception: None

Example: var a = "abcde";

VAR B = String.Find (A, "CD"); // b = 2

VAR C = String.Find (34.2, "de"); // c = -1Var D = String.Find (A, "GZ"); // D = -1

Var E = String.Find (34, "3"); // E = 0

Replace

Program: Eplace (TRING, OLDSUBSTRING, NewsUbstring)

Description: Help new strings, this new string is replaced by the old character transmitted Oldsubstring that is consistent with the string string uses the new string newsubstring string instead. If the two strings are equal, they are defined as consistency.

Parameters: String = String

Oldsubstring = string

NewsUbstring = string

Back to the value: string or invalid

Exception: None

Example: var a = "Hello Joe.What IS UP JOE?";

Var newname = "don";

Var oldname = "joe";

Var c = string.replace (a, oldname, newname); // c = "Hello don.what is up don?"

VAR D = String.Replace (A, OldName, NewName); // c = "Hello Don.What is Up Don?"

ELEMENT

Program: Element (String, Separetor)

Description: The number of elements String String STRING separately separated by symbol Separator is a valid element, which means that this program will never pass back less than or equal to 0.

Parameters: String = String

Separetor = string

Return value: integer or invalid

Exquisite situation: If the Separator is an empty string, return to 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.eferences (";", ";"); // f = 2

Var g = string.efficient (";;,;", ";,"); // g = 4

Separator =;

ELEMENTAT

Procedure: Elementat (String, Index, Separetor)

Description: Look for the String String's INDEX element, which is separated by the separator Separator, and back into the corresponding element.

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, go back to the empty string.

If the index value is a floating point, you must first use float.int () to calculate the correct index value.

Parameters: string = String INDEX = Digital

Separetor = string

Back to the value: string or invalid

Exquisite situation: If the Separator is an empty string, return to invalid

Example: var a = "Hello Joe.What IS 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)

Note: The separated number SEPARATOR that complies with the index value index is removed from the element string String and returns this 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, go back to the empty string.

If the index value is a floating point, you must first use float.int () to calculate the correct index value.

Parameters: String = String

ELEMENT = string

INDEX = number

Separetor = string

Back to the value: string or invalid

Exquisite situation: If the Separator is an empty string, return to 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

Procedure: Replaceat (String, INDEX, SEPARATOR)

Description: In the specific Index element, use the given element Element instead, and return this 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, go back to the empty string.

If the index value is a floating point, you must first use float.int () to calculate the correct index value.

Parameters: String = String

ELEMENT = string

INDEX = number

Separetor = string

Back to the value: string or invalid

Exquisite situation: If the Separator is an empty string, return to 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: Insert the element Element with the corresponding separator Separator into the original string string, element in a specific ELEMENT

If the index value is less than 0, then 0 will be used to index value.

If the index value is greater than the number of elements, the element ELEMENT will attach the string String to the end.

If the string string is a null string, the new string containing the given element Element is returned.

If the index value is a floating point number, you need to use float.int () to calculate the correct index value.

Parameters: String = String

ELEMENT = string

INDEX = number

Separetor = string

Back to the value: string or invalid

Exquisite situation: If the Separator is an empty string, return to 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: Reduce all consecutive spaces in the string String as a space.

Parameters: stromg = string

Back to the value: string or invalid

Exception: 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: Delete all the startings in the string string with continuous spaces.

Parameters: String = String

Back to the value: string or invalid

Exception: 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)

Note: The return value of this program will indicate that String1 and String2 are in terms of language, this relationship is based on the character code of the natural cluster, which is as follows:

If String1 is less than String2, it will be -1.

If string1 is equal to String2, it will be -1.

If String1 is larger than String2, it will be -1.

Parameters: String1 = String

String2 = string

Return value: integer or invalid

Exception: 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)

Description: Back to a string that can represent the value value value Value, this program is the same as WML Script, except for the InvLAID value to return to a "Invalid" string.

Parameters: value = Arbitrary Value

Recycle value: string

Exception: None

Example: var A = string.toString (12); // a = "12"

Var a = string.toString (true); // b = "true"

Format

Procedure: Format (Format, Value)

Description: Convert the value value VALUE into a string, and in accordance with the formatted string provided by Format, this format string can only be placed anywhere, and can be placed anywhere in the string, if More than one format needs to be used, you can use the leftmost format, as for other formats, there is an empty string instead, these formats are as follows:

[width] [. precision] TYPE

The width parameter is non-negative is the minimum number of closures. This parameter controls the minimum number of appearance characters. If the output number is less than the specified width width, it will be added to the left of the string, until the minimum width requirements, width The parameters will never be value Value being deleted. All characters in Value are displayed if the number of words output is greater than a specific width or not specifying the width.

The precision parameter is a non-negative decimal integer. The symbols must be limited to (.) before this quotation, the purpose is to set the accuracy of the input value, this value is related to the format:

D defining the number of digital display, if the number of numbers in the value exceeds the value of Precision, the input value will add 0 on the left, if the number of numbers exceeds the precision value, the value of Value will not be deleted, preset The 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 defining the number of numbers after the decimal decimal. If the decimal decimal point appears, at least one digit after the decimal point, this value will be rounded into the approximate numerical value, the preset precision is 6, if precision is 0 or decimal point ( After no numbers, the decimal point is not displayed. When the number of values ​​after the Value value is less than the value of Precision, the letters 0 are added until filling the field (such as: String.3f ", 1.2) Will be "1.200")

S defining the maximum number of characters to appear, the preset value is all characters, when the width value is greater than the precision value, the width value is negligible, and the width value is different, precision can only cause the floating point value to cause floating point value Enter the value of the value. The TYPE parameter is the only format parameter. After any format column, the Type character determines that the value given into an integer, floating point, or string, the supported Type parameters are as follows:

D integer: The format of the input value [-] DDDD, the DDDD here is one or more decimal numbers.

F floating point number: The format of the input value [-] dddd.dddd, the DDDD here is one or more decimal numbers, the number of numbers and numbers after the number of numbers before the decimal point are related to the number of numbers.

s String: The character's appearance is related to the accuracy.

Percentage characters (%) can be represented by additional percentage characters in the format string (%%).

Parameters: Format = String

Value = Arbitrary value

Back to the value: string or invalid

Exception status; 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"

转载请注明原文地址:https://www.9cbs.com/read-99909.html

New Post(0)