The QString class is a handle class that provides an abstraction of the C style zero-terminated char array. QString inherits QByteArray, which is defined as QArray<char>. (details) (complete member list)
#include <qstring.h>
Inherits QByteArray.
Note that for the QString methods that take a const char * parameter the results are undefined if the QString is not zero-terminated. It is legal for the const char * parameter to be 0.
A QString that has not been assigned to anything is void, i.e. both the length and data pointer is 0. A QString that references the empty string ("", a single '\0' char) is empty. Both void and empty QStrings are legal parameters to the methods. Assigning const char * 0 to QString gives a void QString.
Since QString has both an internal length specifier (from QArray) and a zero-terminator, there will be a conflict if somebody manually inserts a '\0' into the string.
QString s = "networking is fun";
s[10] = 0;
// s will be "networking"
// strlen(s) will be 10
// s.length() is still 17
See handle classes for information about handle classes.
Constructs a void string.
Constructs a shallow copy s.
Constructs a string with room for size characters, including the '\0'-terminator.
Creates a string that is a deep copy of str.
Returns the string data.
Returns the string data.
Counts the number of overlapping occurrences of rx in the string.
QString s = "banana and panama";
QRegExp r = QRegExp("a[nm]a", TRUE, FALSE);
s.contains( r ); // 4 matches
Returns the number of times the character c occurs in the string. The match is case sensitive if and only if cs is TRUE, or case insensitive if cs if FALSE.
Returns the number of times str occurs in the string.
The match is case sensitive if cs is TRUE, or case insensitive if cs if FALSE.
This function counts overlapping substrings, for example, "banana" contains two occurrences of "ana".
See also: findRev().
Fills the string with len bytes of value c, followed by a '\0'-terminator.
If len is negative, then the current string length will be used.
Returns FALSE is len is nonnegative and there is no memory to resize the string, otherwise TRUE is returned.
Finds the first occurrence of the character c, starting at position index. The search is case sensitive if cs is TRUE and case insensitive if cs is FALSE.
Returns the position of c, or -1 if c could not be found.
Finds the first occurrence of the string str, starting at position index. The search is case sensitive if cs is TRUE and case insensitive if cs is FALSE.
Returns the position of str, or -1 if str could not be found.
Finds the first occurrence of the regular expression rx, starting at position index and searching backwards.
The search will start from the end of the string if index is negative.
Returns the position of the next match (backwards), or -1 if rx was not found.
Finds the first occurrence of the character c, starting at position index and searching backwards. The search is case sensitive if cs is TRUE and case insensitive if cs is FALSE.
Returns the position of c, or -1 if c could not be found.
Finds the first occurrence of the string str, starting at position index and searching backwards. The search is case sensitive if cs is TRUE and case insensitive if cs is FALSE.
Returns the position of str, or -1 if str could not be found.
Insert s into the string at position index. If index is too large, s is inserted at the end of the string.
QString a = "I like fish";
a.insert(a, 2, "don't "); // becomes: "I don't like fish"
Insert c into the string at (before) position index. If index is too large, c is inserted at the end of the string.
QString a = "Yes";
a.insert( 12528, '!'); // ok, becomes "Yes!"
See also: remove(), replace().
Returns TRUE is the string is empty (i.e. if length() == 0).
Returns a substring that contains the len leftmost characters of this string. A deep copy of this string will be returned if len exceeds the length of this string.
Returns a string of length width (plus '\0') that contains this string and padded by the fill character.
If the length of this string exceeds width, then the result string will be a truncated copy of this string.
QString s("apple");
QString t = s.leftJustify(8, '.'); // t == "apple..."
See also: rightJustify().
Returns the length of the string, excluding the '\0'-terminator. Void strings (null pointers) have zero length.
Converts the string to lower case and returns a reference to this string. At present it only handles 7-bit ASCII, or whatever the system tolower() handles (if $LC_CTYPE is set, most unices do the Right Thing).
See also: upper().
To do:
Returns a substring that contains the len characters of this string, starting at position index.
Returns a void string if this string is empty or index is out of range.
Returns TRUE if it is a null string, otherwise FALSE.
Appends str to this string and returns a reference to the string.
Appends c to this string and returns a reference to the string.
Assigns a shallow copy of s and return a reference to this string.
Assigns a deep copy of str and return a reference to this string.
Removes len characters starting at position index from the string.
If index is too big, nothing happens. If index is valid, but len is too large, the rest of the string is removed.
QString a = "It's a black rug";
a.remove( 8, 6 ); // becomes "It's a bug"
See also: insert(), replace().
Replaces every occurrence of rx in the string with str. Returns a reference to the string.
QString s = "banana";
s.replace( QRegExp("a.*a"), "" ); // becomes "b"
Replaces len characters starting at position index from the string with s, and returns a reference to the string.
If index is too big, nothing is deleted and s is inserted at the end of the string. If index is valid, but len is too large, str replaces the rest of the string.
QString a = "Say yes!";
a.replace( 4, 3, "NO" ); // becomes "Say NO!"
Extends or shrinks the string to len bytes, including the '\0'-terminator. A \0-terminator is set at position len - 1 unless len == 0
Returns a substring that contains the len rightmost characters of this string. A deep copy of this string will be returned if len exceeds the length of this string.
Returns a string of length width (plus '\0') that contains pad characters followed by this string.
If the length of this string exceeds width, then the result string will be a truncated copy of this string.
QString s("pie");
QString t = s.rightJustify(8, '.'); // t == ".....pie"
See also: leftJustify().
Sets the characted at position index to c and expands the string is necessary.
Returns FALSE if this index was out of range and the string could not be expanded, otherwise TRUE.
Sets the string to the numerical value of n. Returns a reference to this string.
Sets the string to the numerical unsigned value of n. Returns a reference to this string.
Sets the string to the numerical value of n. Returns a reference to the string.
Sets the string to the numerical unsigned value of n. Returns a reference to the string.
Sets the string to the numerical value of n. Returns a reference to the string.
Sets the string to the numerical unsigned value of n. Returns a reference to the string.
Sets the string to the numerical value of n.
Arguments:
Sets the string to the numerical value of n.
Arguments:
Makes a deep copy of str without dereferencing the current string, i.e. all strings that share data will be modified. Returns a reference to this string.
Strips white space away from the start and end of the string, and change all internal white space (any sequence of ASCII codes 9, 10, 11, 12, 13 and 32) into a single space.
QString a = " lots\t of\nwhite space ";
a.simplifyWhiteSpace(); // a: " lots of white space "
See also: stripWhiteSpace().
Implemented as a call to the native vsprintf() (see your C-library manual).
Many vsprintf() implementations have some sort of arbitrary and undocumented limit, some crash your program when you exceed it. If your string is shorter than 256 characters, Qt sprintf() calls resize(256) to decrease the chance of crashing.
Strips white space from the beginning and the end of the string.
See also: simplifyWhiteSpace().
Returns the string converted to a double
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Returns the string converted to a float
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Returns the string converted to a int
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Returns the string converted to a long
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Returns the string converted to a short
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Returns the string converted to an unsigned int
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Returns the string converted to an unsigned long
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Returns the string converted to an unsigned short
value.
If ok is non-NULL, *ok will be set to TRUE if there are no conceivable errors, and FALSE if the string is not a number at all, or if it has trailing garbage.
Converts the string to upper case and returns a reference to the string. At present it only handles 7-bit ASCII, or whatever the system toupper() handles (if $LC_CTYPE is set, most unices do the Right Thing).
See also: lower().
To do:
Some versions of memmove puke on your data if your source and destination blocks overlap.
Not qmemmove.
Arguments:
Allocates space for a copy of the string, copies it, and returns a pointer to the copy.
If str1 and str2 are both non-NULL, qstricmp() returns negative, 0 or positive, just like the C library's stricmp(). If either str1 or str2 but not both are NULL, qstricmp() returns a random non-zero value. If both are NULL, qstricmp() returns 0.
See also: qstrnicmp().
If str1 and str2 are both non-NULL, qstrnicmp() returns negative, 0 or positive, just like the C library's strnicmp() or strncasecmp. If either str1 or str2 but not both are NULL, qstrnicmp() returns a random non-zero value. If both are NULL, qstrnicmp() returns 0. Also see qstricmp().
See also: qstricmp().
This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.
It was generated from the following files: