[Prev: RegExp] [Home] [Next: Built-in Objects]
A String is a sequence of zero or more Unicode characters. Qt Script's String class uses the Qt QString class's functions and syntax.
Strings can be created and concatenated as follows.
var text = "this is a"; var another = new String( "text" ); var concat = text + " " + another; // concat == "this is a text"
The length property describes the length of the string.
fromCharCode( code1, code2, ... )
var s = String.fromCharCode( 65, 66, 67, 68 ); System.println( s ); // prints "ABCD"
Returns a string made up of the characters with code code1, code2, etc, according to the character codes of the UTF-16 character table.
charAt( pos )
Returns the character in the string at position pos. If the position is out of bounds, undefined is returned.
charCodeAt( pos )
Returns the character code of the character at position pos in the string. If the position is out of bounds, undefined is returned.
indexOf( pattern, pos )
Returns the index of pattern in the string, starting at position pos. If no position is specified, the function starts at the beginning of the string. If the pattern is not found in the string, -1 is returned.
lastIndexOf( pattern pos )
Returns the last index of pattern in the string, starting at position pos. If no position is specified, the function starts at the end of the string. If the pattern is not found in the string, -1 is returned.
match( regexp )
Returns the matched pattern if this string matches the pattern defined by regexp. If regexp is not a regular expression, undefined is returned.
search( regexp )
Returns the position of the pattern regexp if regexp is a regular expression and it matches the string; otherwise returns undefined.
replace( pattern, newvalue )
Replaces the first occurrence of pattern in the string with newvalue if the pattern is found in the string. A copy of the string or the modified string is returned. pattern can be a regular expression.
split( pattern )
Returns an array of string containing this string split on each occurrence of pattern. The pattern can be a regular expression.
substr( index, length )
Returns a substring of this string, starting at index, which is length long.
substring( index, length )
Same as substr.
toLowerCase()
Returns a lowercase copy of this string.
lower()
Returns a lowercase copy of this string.
toUpperCase()
Returns an uppercase copy of this string.
upper()
Returns an uppercase copy of this string.
isEmpty()
Returns true if this string is empty, i.e. has a length of 0; otherwise false.
left( length )
Returns a substring containing the length leftmost characters of this string.
right( length )
Returns a substring containing the length rightmost characters of this string.
mid( start, length )
Same as substring above.
find( pattern, pos )
Returns the first position of pattern after pos. pattern can be a regular expression. If the pattern is not found, -1 is returned. If pos is not specified, position 0 is used.
findRev( pattern, pos )
Returns the first position of pattern before pos, searching backward. pattern can be a regular expression. If pattern is not found, -1 is returned. If pos is not specified, position 0 is used.
startsWith( pattern )
Returns true if the string starts with pattern; otherwise false.
endsWith( patterh )
Returns true if the string ends with pattern; otherwise false.