String
Description
The String class is a data type that represents a string of characters. The String class provides methods and properties that let you manipulate primitive string value types.
API overview
Constructor
String
()
Functions
Public functions
| charAt ( index: Number ): String |
native Gets the character at the specified index |
| charCodeAt ( index: Number ): Number |
native Gets the character code for the specified index |
| concat ( args: Vector.<Object> ): String |
native Concatenates a list of String%s onto the String |
| find ( pattern: String ): Vector.<String> |
native Regex pattern matching using Lua regex rules |
| format ( formatString: String , args: Vector.<Object> ): String |
static native Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string) |
| fromCharCode ( code: Number ): String |
static native Converts a char code to s String value |
| indexOf ( val: String , startIndex: Number = 0 ): Number |
native Gets the index of a search val in the string, starting at the index specified |
| isNullOrEmpty ( c: String ): Boolean |
static Determines if a string is either null or empty |
| isWhitespace ( c: String ): Boolean |
static Determines if a string is a whitespace character |
| lastIndexOf ( val: String , startIndex: Number = ): Number |
native Gets the last index of a search val in the string, starting at the index specified |
| lpad ( s: String , c: String , l: Number ): String |
static Left pad the string s with the string c up to the width of l |
| rpad ( s: String , c: String , l: Number ): String |
static Right pad the string s with the string c up to the width of l |
| slice ( startIndex: Number = 0 , endIndex: Number = 0x7fffffff ): String |
native Returns a string that includes the startIndex character and all characters up to, but not including, the endIndex character |
| split ( delimiter: String ): Vector.<String> |
native Splits a String object into an array of substrings by dividing it wherever the specified delimiter parameter occurs |
| substr ( startIndex: Number = 0 , len: Number = ): String |
native Returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len |
| substring ( startIndex: Number = 0 , endIndex: Number = ): String |
native Returns a string consisting of the character specified by startIndex and all characters up to endIndex - 1 |
| toBoolean (): Boolean |
native Safely evaluate the String to a Boolean value |
| toLocaleLowerCase (): String |
native Converts every character in the String to lower case |
| toLocaleUpperCase (): String |
native Converts every character in the String to upper case |
| toLowerCase (): String |
native Converts every character in the String to lower case |
| toMD5 (): String |
native Safely evaluate the String to an MD5 encoded string value |
| toNumber (): Number |
native Safely evaluate the String to a Number value |
| toSHA2 (): String |
native Safely evaluate the String to a SHA2 256 encoded string value |
| toUpperCase (): String |
native Converts every character in the String to upper case |
| trim (): String | native |
Constructor
String ()
Attributes
Functions
charAt ( index: Number ): String
native
Gets the character at the specified index.
Parameters
| index: Number | The index of the character. |
Returns
| String | The character at the specified index, Null if index is out of range. |
charCodeAt ( index: Number ): Number
native
Gets the character code for the specified index.
Parameters
| index: Number | The index of the character code. |
Returns
| Number | The character code for the specified index, -1 if the index is out of range. |
concat ( args: Vector.<Object> ): String
native
Concatenates a list of String%s onto the String.
Parameters
| args: Vector.<Object> | The list of String instances to concatenate onto ths String. |
Returns
| String | The concatenated String. |
find ( pattern: String ): Vector.<String>
native
Regex pattern matching using Lua regex rules.
Note that without captures (the () syntax) you will get zero results.
See also:
http://lua-users.org/wiki/PatternsTutorial
Parameters
| pattern: String | The Regex pattern. |
Returns
| Vector | A Vector of String matches. |
format ( formatString: String , args: Vector.<Object> ): String
static native
Returns a formatted version of its variable number of arguments following the description given in its first argument (which must be a string). The format string follows the same rules as the printf family of standard C functions. The only differences are that the options/modifiers *, l, L, n, p, and h are not supported and that there is an extra option, q. The q option formats a string in a form suitable to be safely read back by the LoomScript interpreter: the string is written between double quotes, and all double quotes, newlines, embedded zeros, and backslashes in the string are correctly escaped when written. For instance, the call String.format('%q', 'a string with "quotes" and \n new line') will produce the string:
"a string with \"quotes\" and \ new line" The options c, d, E, e, f, g, G, i, o, u, X, and x all expect a number as argument, whereas q and s expect a string.
This function does not accept string values containing embedded zeros, except as arguments to the q option.
Parameters
| formatString: String | the string format |
| args: Vector.<Object> |
Returns
| String | the formatted string based on the input args |
fromCharCode ( code: Number ): String
static native
Converts a char code to s String value.
Parameters
| code: Number | The char code to convert |
Returns
| String | A String value that represents the char code. |
getFullTypeName
(): String
Inherited from Object
native
Gets the fully qualified type name of the Object. The fully qualified type name includes the package of the type.
Returns
| String | fully qualified type name of the Object. |
getType
(): Type
Inherited from Object
native
Gets the Type that describes the Object.
Returns
| Type | The Type that describes the object. |
getTypeName
(): String
Inherited from Object
native
Gets the type name of the Object.
Returns
| String | type name of the Object. |
indexOf ( val: String , startIndex: Number = 0 ): Number
native
Gets the index of a search val in the string, starting at the index specified.
Parameters
| val: String | The String to search. |
| startIndex: Number = 0 | The index to begin the search on. |
Returns
| Number | The index of the first occurance of the seach string, -1 if the search string does not exist. |
isNullOrEmpty ( c: String ): Boolean
static
Determines if a string is either null or empty.
Parameters
| c: String | The string to check |
Returns
| Boolean | a Boolean value indicating the result of the test. |
isWhitespace ( c: String ): Boolean
static
Determines if a string is a whitespace character.
Parameters
| c: String | The string to check |
Returns
| Boolean | a Boolean value indicating the result of the test. |
lastIndexOf ( val: String , startIndex: Number = ): Number
native
Gets the last index of a search val in the string, starting at the index specified.
Parameters
| val: String | The String to search. |
| startIndex: Number = | The index to begin the search on. |
Returns
| Number | The index of the last occurance of the seach string, -1 if the search string does not exist. |
lpad ( s: String , c: String , l: Number ): String
static
Left pad the string s with the string c up to the width of l. c is added to the left of s until it reaches the length of l.
Parameters
| s: String | The string to add left padding on. |
| c: String | The string to use as padding, usually a single character. |
| l: Number | The length or width of the final string. If the string is already as long or longer, it is returned unmodified. |
Returns
| String | The new padded string. |
rpad ( s: String , c: String , l: Number ): String
static
Right pad the string s with the string c up to the width of l. c is added to the right of s until it reaches the length of l.
Parameters
| s: String | The string to add right padding on. |
| c: String | The string to use as padding, usually a single character. |
| l: Number | The length or width of the final string. If the string is already as long or longer, it is returned unmodified. |
Returns
| String | The new padded string. |
slice ( startIndex: Number = 0 , endIndex: Number = 0x7fffffff ): String
native
Returns a string that includes the startIndex character and all characters up to, but not including, the endIndex character.
Parameters
| startIndex: Number = 0 | The zero-based index of the starting point for the slice. If startIndex is a negative number, the slice is created from right-to-left, where -1 is the last character. |
| endIndex: Number = 0x7fffffff | An integer that is one greater than the index of the ending point for the slice. The character indexed by the endIndex parameter is not included in the extracted string. If endIndex is a negative number, the ending point is determined by counting back from the end of the string, where -1 is the last character. The default is the maximum value allowed for an index. If this parameter is omitted, String.length is used. |
Returns
| String | A substring based on the specified indices. |
split ( delimiter: String ): Vector.<String>
native
Splits a String object into an array of substrings by dividing it wherever the specified delimiter parameter occurs.
Parameters
| delimiter: String | The pattern that specifies where to split this String. |
substr ( startIndex: Number = 0 , len: Number = ): String
native
Returns a substring consisting of the characters that start at the specified startIndex and with a length specified by len.
Parameters
| startIndex: Number = 0 | An integer that specified the index of the first character to be used to create the substring. If startIndex is a negative number, the starting index is determined from the end of the string, where -1 is the last character. |
| len: Number = | The number of characters in the substring being created. The default value is the maximum value allowed. If len is not specified, the substring includes all the characters from startIndex to the end of the string. |
Returns
| String | A substring based on the specified indices. |
substring ( startIndex: Number = 0 , endIndex: Number = ): String
native
Returns a string consisting of the character specified by startIndex and all characters up to endIndex - 1. If endIndex is not specified, String.length is used. If the value of startIndex equals the value of endIndex, the method returns an empty string. If the value of startIndex is greater than the value of endIndex, the parameters are automatically swapped before the function executes. The original string is unmodified.
Parameters
| startIndex: Number = 0 | An integer specifying the index of the first character used to create the substring. Valid values for startIndex are 0 through String.length. If startIndex is a negative value, 0 is used. |
| endIndex: Number = | An integer that is one greater than the index of the last character in the extracted substring. Valid values for endIndex are 0 through String.length. The character at endIndex is not included in the substring. The default is the maximum value allowed for an index. If this parameter is omitted, String.length is used. If this parameter is a negative value, 0 is used. |
toBoolean (): Boolean
native
Safely evaluate the String to a Boolean value.
Returns
| Boolean | The Boolean value evaluated from the String. |
toLocaleLowerCase (): String
native
Converts every character in the String to lower case.
Returns
| String | The lowercased String. |
toLocaleUpperCase (): String
native
Converts every character in the String to upper case.
Returns
| String | The uppercased String. |
toLowerCase (): String
native
Converts every character in the String to lower case.
Returns
| String | The lowercased String. |
toMD5 (): String
native
Safely evaluate the String to an MD5 encoded string value.
Returns
| String | The MD5 String value evaluated from the String. |
toNumber (): Number
native
Safely evaluate the String to a Number value.
Returns
| Number | The Number value evaluated from the String. |
toSHA2 (): String
native
Safely evaluate the String to a SHA2 256 encoded string value.
Returns
| String | The SHA2 String value evaluated from the String. |
toString
(): String
Inherited from Object
native
Returns a String that describes the Object. This can be overriden to provide extra details when printing objects using trace().
Returns
| String | String that described the Object. |