📄 qstring.3qt
字号:
.br QString s = "banana";.br s.replace( QRegExp("^[bn]a"), " " ); // becomes " nana".br.br QString s = "banana";.br s.replace( QRegExp("^[bn]a"), "" ); // NOTE! becomes "".fi.PPSee also find() and findRev()..SH "QString & QString::replace ( uint index, uint len, const QChar * s, uint slen )"Replaces \fIlen\fR characters starting at position \fIindex\fR by \fIslen\fR units ot QChar data from \fIs,\fR and returns a reference to the string..PPSee also insert() and remove()..SH "QString & QString::replace ( uint index, uint len, const QString & s )"Replaces \fIlen\fR characters starting at position \fIindex\fR from the string with \fIs,\fR and returns a reference to the string..PPIf \fIindex\fR is too big, nothing is deleted and \fIs\fR is inserted at the end of the string. If \fIindex\fR is valid, but \fIlen\fR is too large, \fIstr\fR replaces the rest of the string..PP.nf.br QString s = "Say yes!";.br s.replace( 4, 3, "NO" ); // s == "Say NO!".fi.PPSee also insert() and remove()..PPExamples:.(lqmag/qmag.cpp.)l.SH "QString QString::right ( uint len ) const"Returns a substring that contains the \fIlen\fR rightmost characters of the string..PPThe whole string is returned if \fIlen\fR exceeds the length of the string..PPExample:.PP.nf.br QString s = "Pineapple";.br QString t = s.right( 5 ); // t == "apple".fi.PPSee also left(), mid() and isEmpty()..SH "QString QString::rightJustify ( uint width, QChar fill=' ', bool truncate=FALSE ) const"Returns a string of length \fIwidth\fR that contains pad characters followed by the string..PPIf the length of the string exceeds \fIwidth\fR and \fItruncate\fR is FALSE, then the returned string is a copy of the string. If the length of the string exceeds \fIwidth\fR and \fItruncate\fR is TRUE, then the returned string is a left(\fIwidth).\fR.PPExample:.PP.nf.br QString s("pie");.br QString t = s.rightJustify(8, '.'); // t == ".....pie".fi.PPSee also leftJustify()..SH "void QString::setExpand ( uint index, QChar c )"\fBThis function is obsolete.\fR It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code..PPSets the character at position \fIindex\fR to \fIc\fR and expands the string if necessary, filling with spaces..PPThis method is redundant in Qt 2.x, because operator[] will expand the string as necessary..SH "QString & QString::setLatin1 ( const char * str, int len=-1 )"Sets this string to \fIstr,\fR interpreted as a classic Latin 1 C string. If the \fIlen\fR argument is negative (default), it is set to strlen(str)..PPIf \fIstr\fR is 0 a null string is created. If \fIstr\fR is "" an empty string is created..PPSee also isNull() and isEmpty()..SH "QString & QString::setNum ( double n, char f='g', int prec=6 )"Sets the string to the printed value of \fIn,\fR formatted in the \fIf\fR format with \fIprec\fR precision, and returns a reference to the string..PP\fIf\fR can be 'f', 'F', 'e', 'E', 'g' or 'G', all of which have the same meaning as for sprintf()..SH "QString & QString::setNum ( int n, int base=10 )"Sets the string to the printed value of \fIn\fR and returns a reference to the string..SH "QString & QString::setNum ( long n, int base=10 )"Sets the string to the printed value of \fIn\fR and returns a reference to the string..PPThe value is converted to \fIbase\fR notation (default is decimal). The base must be a value from 2 to 36..SH "QString & QString::setNum ( short n, int base=10 )"Sets the string to the printed value of \fIn\fR and returns a reference to the string..SH "QString & QString::setNum ( uint n, int base=10 )"Sets the string to the printed unsigned value of \fIn\fR and returns a reference to the string..SH "QString & QString::setNum ( ulong n, int base=10 )"Sets the string to the printed unsigned value of \fIn\fR and returns a reference to the string..PPThe value is converted to \fIbase\fR notation (default is decimal). The base must be a value from 2 to 36..SH "QString & QString::setNum ( ushort n, int base=10 )"Sets the string to the printed unsigned value of \fIn\fR and returns a reference to the string..SH "QString & QString::setNum ( float n, char f='g', int prec=6 )"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "QString& QString::setUnicode ( const QChar * unicode, uint len )"Resizes the string to \fIlen\fR unicode characters and copies \fIunicode\fR into the string. If \fIunicode\fR is null, nothing is copied, but the string is resized to \fIlen\fR anyway. If \fIlen\fR is zero, the string becomes a null string..PPSee also setLatin1() and isNull()..SH "QString& QString::setUnicodeCodes ( const ushort * unicode_as_ushorts, uint len )"Resizes the string to \fIlen\fR unicode characters and copies \fIunicode_as_ushorts\fR into the string (on some X11 client platforms this will involve a byte-swapping pass)..PPIf \fIunicode\fR is null, nothing is copied, but the string is resized to \fIlen\fR anyway. If \fIlen\fR is zero, the string becomes a null string..PPSee also setLatin1() and isNull()..SH "QString QString::simplifyWhiteSpace () const"Returns a new string that has white space removed from the start and the end, plus any sequence of internal white space replaced with a single space (ASCII 32)..PPWhite space means any character for which QChar::isSpace() returns TRUE. This includes ASCII characters 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space)..PP.nf.br QString s = " lots\\t of\\nwhite space ";.br QString t = s.simplifyWhiteSpace(); // t == "lots of white space".fi.PPSee also stripWhiteSpace()..SH "QString & QString::sprintf ( const char * cformat, ... )"Safely builds a formatted string from a format string and an arbitrary list of arguments. The format string supports all the escape sequences of printf() in the standard C library..PPThe %s escape sequence expects a utf8() encoded string. The format string \fIcformat\fR is expected to be in latin1. If you need a unicode format string, use QString::arg() instead. For typesafe string building, with full Unicode support, you can use QTextOStream like this:.PP.nf.br QString str;.br QString s = ...;.br int x = ...;.br QTextOStream(&str) << s << " : " << x;.fi.PPFor translations, especially if the strings contains more than one escape sequence, you should consider using the arg() function instead. This allows the order of the replacements to be controlled by the translator, and has Unicode support..PPSee also arg()..PPExamples:.(lxform/xform.cpp layout/layout.cpp drawdemo/drawdemo.cpp popup/popup.cpp progress/progress.cpp qmag/qmag.cpp forever/forever.cpp scrollview/scrollview.cpp movies/main.cpp picture/picture.cpp.)l.SH "bool QString::startsWith ( const QString & s ) const"Returns whether the strings starts with \fIs,\fR or not..SH "QString QString::stripWhiteSpace () const"Returns a new string that has white space removed from the start and the end..PPWhite space means any character for which QChar::isSpace() returns TRUE. This includes ASCII characters 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space)..PPExample:.PP.nf.br QString s = " space ";.br QString t = s.stripWhiteSpace(); // t == "space".fi.PPSee also simplifyWhiteSpace()..SH "double QString::toDouble ( bool * ok=0 ) const"Returns the string converted to a \fCdouble\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "float QString::toFloat ( bool * ok=0 ) const"Returns the string converted to a \fCfloat\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "int QString::toInt ( bool * ok=0, int base=10 ) const"Returns the string converted to a \fCint\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "long QString::toLong ( bool * ok=0, int base=10 ) const"Returns the string converted to a \fClong\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "short QString::toShort ( bool * ok=0, int base=10 ) const"Returns the string converted to a \fCshort\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "uint QString::toUInt ( bool * ok=0, int base=10 ) const"Returns the string converted to an \fCunsigned int\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "ulong QString::toULong ( bool * ok=0, int base=10 ) const"Returns the string converted to an \fCunsigned long\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "ushort QString::toUShort ( bool * ok=0, int base=10 ) const"Returns the string converted to an \fCunsigned short\fR value..PPIf \fIok\fR is non-null, \fI*ok\fR is 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..SH "void QString::truncate ( uint newLen )"Truncates the string at position \fInewLen\fR if newLen is less than the current length . Otherwise, nothing happens..PPExample:.PP.nf.br QString s = "truncate this string";.br s.truncate( 5 ); // s == "trunc".fi.PPIn Qt 1.x, it was possible to "truncate" a string to a longer length. This is no longer possible..SH "const QChar* QString::unicode () const"Returns the Unicode representation of the string. The result remains valid until the string is modified..SH "QString QString::upper () const"Returns a new string that is the string converted to upper case..PPExample:.PP.nf.br QString s("TeX");.br QString t = s.upper(); // t == "TEX".fi.PPSee also lower()..SH "QCString QString::utf8 () const"Returns the string encoded in UTF8 format..PPSee QTextCodec for more diverse coding/decoding of Unicode strings..PPSee also QString::fromUtf8(), local8Bit() and latin1()..SH "QString QString::visual ( int index = 0, int len = -1 )"This function returns the QString ordered visually. Useful for painting the string or when transforming to a visually ordered encoding..SH RELATED FUNCTION DOCUMENTATION.SH "QDataStream & operator>> (QDataStream & s, QString & str)"Reads a string from the stream..PPSee also Format of the QDataStream operators.SH "QString operator+ (const char * s1, const QString & s2)"Returns the concatenated string of s1 and s2..SH "bool operator<= (const char * s1, const QString & s2)"Returns TRUE if \fIs1\fR is alphabetically less than or equal to \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) <= 0\fR.SH "QString operator+ (const QString & s1, const char * s2)"Returns the concatenated string of s1 and s2..SH "QString operator+ (const QString & s1, const QString & s2)"Returns the concatenated string of s1 and s2..SH "QDataStream & operator<< (QDataStream & s, const QString & str)"Writes a string to the stream..PPSee also Format of the QDataStream operators.SH "bool operator== (const QString & s1, const QString & s2)"Returns TRUE if the two strings are equal, or FALSE if they are different. A null string is different from an empty, non-null string..PPEquivalent to \fCqstrcmp(s1,s2) == 0\fR.SH "bool operator!= (const QString & s1, const QString & s2)"Returns TRUE if the two strings are different, or FALSE if they are equal..PPEquivalent to \fCqstrcmp(s1,s2) != 0\fR.SH "bool operator!= (const QString & s1, const char * s2)"Returns TRUE if the two strings are different, or FALSE if they are equal..PPEquivalent to \fCqstrcmp(s1,s2) != 0\fR.SH "bool operator< (const char * s1, const QString & s2)"Returns TRUE if \fIs1\fR is alphabetically less than \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) < 0\fR.SH "bool operator>= (const char * s1, const QString & s2)"Returns TRUE if \fIs1\fR is alphabetically greater than or equal to \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) >= 0\fR.SH "QString operator+ (char c, const QString & s)"Returns the concatenated string of c and s..SH "bool operator<= (const QString & s1, const char * s2)"Returns TRUE if \fIs1\fR is alphabetically less than or equal to \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) <= 0\fR.SH "QString operator+ (const QString & s, char c)"Returns the concatenated string of s and c..SH "bool operator> (const char * s1, const QString & s2)"Returns TRUE if \fIs1\fR is alphabetically greater than \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) > 0\fR.SH "bool operator< (const QString & s1, const char * s2)"Returns TRUE if \fIs1\fR is alphabetically less than \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) < 0\fR.SH "bool operator!= (const char * s1, const QString & s2)"Returns TRUE if the two strings are different, or FALSE if they are equal..PPEquivalent to \fCqstrcmp(s1,s2) != 0\fR.SH "bool operator== (const QString & s1, const char * s2)"Returns TRUE if the two strings are equal, or FALSE if they are different..PPEquivalent to \fCqstrcmp(s1,s2) == 0\fR.SH "bool operator== (const char * s1, const QString & s2)"Returns TRUE if the two strings are equal, or FALSE if they are different..PPEquivalent to \fCqstrcmp(s1,s2) == 0\fR.SH "bool operator> (const QString & s1, const char * s2)"Returns TRUE if \fIs1\fR is alphabetically greater than \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) > 0\fR.SH "bool operator>= (const QString & s1, const char * s2)"Returns TRUE if \fIs1\fR is alphabetically greater than or equal to \fIs2,\fR otherwise FALSE..PPEquivalent to \fCqstrcmp(s1,s2) >= 0\fR.SH "SEE ALSO".BR http://doc.trolltech.com/qstring.html.SH COPYRIGHTCopyright 1992-2000 Trolltech AS, http://www.trolltech.com/. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -