|Home | Tutorial | Classes | Functions | QSA Workbench | Language | Qt API | QSA Articles Qt Script for Applications

[Prev: RegExp] [Home] [Next: Built-in Objects]

String

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"
String Properties
length

The length property describes the length of the string.

String Functions
fromCharCode ( static function )

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

charAt( pos )

Returns the character in the string at position pos. If the position is out of bounds, undefined is returned.

charCodeAt

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

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

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

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

search( regexp )

Returns the position of the pattern regexp if regexp is a regular expression and it matches the string; otherwise returns undefined.

replace

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

split( pattern )

Returns an array of string containing this string split on each occurrence of pattern. The pattern can be a regular expression.

substr

substr( index, length )

Returns a substring of this string, starting at index, which is length long.

substring

substring( index, length )

Same as substr.

toLowerCase

toLowerCase()

Returns a lowercase copy of this string.

lower

lower()

Returns a lowercase copy of this string.

toUpperCase

toUpperCase()

Returns an uppercase copy of this string.

upper

upper()

Returns an uppercase copy of this string.

isEmpty

isEmpty()

Returns true if this string is empty, i.e. has a length of 0; otherwise false.

left

left( length )

Returns a substring containing the length leftmost characters of this string.

right

right( length )

Returns a substring containing the length rightmost characters of this string.

mid

mid( start, length )

Same as substring above.

find

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

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

startsWith( pattern )

Returns true if the string starts with pattern; otherwise false.

endsWith

endsWith( patterh )

Returns true if the string ends with pattern; otherwise false.

[Prev: RegExp] [Home] [Next: Built-in Objects]


Copyright © 2001-2003 TrolltechTrademarks
QSA version 1.0.0