📄 qstring.3qt
字号:
.nf.br QString a( "" );.br a.isEmpty(); // TRUE.br a.isNull(); // FALSE.br.br QString b;.br b.isEmpty(); // TRUE.br b.isNull(); // TRUE.br.fi.PPSee also isNull() and length()..PPExamples:.)l addressbook/mainwindow.cpp, hello/main.cpp, helpviewer/helpwindow.cpp, mdi/application.cpp, network/networkprotocol/nntp.cpp, qmag/qmag.cpp and qwerty/qwerty.cpp..SH "bool QString::isNull () const"Returns TRUE if the string is null. A null string is always empty..PP.nf.br QString a; // a.unicode() == 0, a.length() == 0.br a.isNull(); // TRUE, because a.unicode() == 0.br a.isEmpty(); // TRUE.br.fi.PPSee also isEmpty() and length()..PPExamples:.)l i18n/main.cpp and qdir/qdir.cpp..SH "const char * QString::latin1 () const"Returns a Latin-1 representation of the string. Note that the returned value is undefined if the string contains non-Latin-1 characters. If you want to convert strings into formats other than Unicode, see the QTextCodec classes..PPThis function is mainly useful for boot-strapping legacy code to use Unicode..PPThe result remains valid so long as one unmodified copy of the source string exists..PPSee also utf8() and local8Bit()..PPExamples:.)l fileiconview/qfileiconview.cpp and network/networkprotocol/nntp.cpp..SH "QString QString::left ( uint len ) const"Returns a substring that contains the \fIlen\fR leftmost characters of the string..PPThe whole string is returned if \fIlen\fR exceeds the length of the string..PP.nf.br QString s = "Pineapple";.br QString t = s.left( 4 ); // t == "Pine".br.fi.PPSee also right(), mid() and isEmpty()..SH "QString QString::leftJustify ( uint width, QChar fill = ' ', bool truncate = FALSE ) const"Returns a string of length \fIwidth\fR that contains this string padded by the \fIfill\fR character..PPIf \fItruncate\fR is FALSE and the length of the string is more than \fIwidth\fR, then the returned string is a copy of the string..PPIf \fItruncate\fR is TRUE and the length of the string is more than \fIwidth\fR, then any characters in a copy of the string after length \fIwidth\fR are removed, and the copy is returned..PP.nf.br QString s( "apple" );.br QString t = s.leftJustify( 8, '.' ); // t == "apple...".br.fi.PPSee also rightJustify()..SH "uint QString::length () const"Returns the length of the string..PPNull strings and empty strings have zero length..PPSee also isNull() and isEmpty()..PPExamples:.)l fileiconview/qfileiconview.cpp, network/networkprotocol/nntp.cpp and rot13/rot13.cpp..SH "QCString QString::local8Bit () const"Returns the string encoded in a locale-specific format. On X11, this is the QTextCodec::codecForLocale(). On Windows, it is a system-defined encoding..PPSee QTextCodec for more diverse coding/decoding of Unicode strings..PPSee also QString::fromLocal8Bit(), latin1() and utf8()..SH "int QString::localeAwareCompare ( const QString & s1, const QString & s2 )\fC [static]\fR"Compares \fIs1\fR with \fIs2\fR and returns an integer less than, equal to, or greater than zero if \fIs1\fR is less than, equal to, or greater than \fIs2\fR..PPThe comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user..PPBugs and limitations:.TPThis function is only implemented on Windows. Elsewhere, it is a synonym for QString::compare()..IP.PPSee also QString::compare() and QTextCodec::locale()..SH "int QString::localeAwareCompare ( const QString & s ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPCompares this string with \fIs\fR..SH "QString QString::lower () const"Returns a string that is the string converted to lowercase..PP.nf.br QString string( "TROlltECH" );.br str = string.lower(); // str == "trolltech".br.fi.PPSee also upper()..PPExample: scribble/scribble.cpp..SH "QString QString::mid ( uint index, uint len = 0xffffffff ) const"Returns a string that contains the \fIlen\fR characters of this string, starting at position \fIindex\fR..PPReturns a null string if the string is empty or \fIindex\fR is out of range. Returns the whole string from \fIindex\fR if \fIindex+len\fR exceeds the length of the string..PP.nf.br QString s( "Five pineapples" );.br QString t = s.mid( 5, 4 ); // t == "pine".br.fi.PPSee also left() and right()..PPExamples:.)l network/mail/smtp.cpp and qmag/qmag.cpp..SH "QString QString::number ( long n, int base = 10 )\fC [static]\fR"A convenience function that returns a string equivilant of the number \fIn\fR to base \fIbase\fR, which is 10 by default and must be between 2 and 36..PP.nf.br long a = 63;.br QString str = QString::number( a, 16 ); // str == "3f".br QString str = QString::number( a, 16 ).upper(); // str == "3F".br.fi.PPSee also setNum()..PPExamples:.)l action/application.cpp, application/application.cpp, fonts/simple-qfont-demo/viewer.cpp, helpviewer/helpwindow.cpp, mdi/application.cpp and sql/overview/extract/main.cpp..SH "QString QString::number ( ulong n, int base = 10 )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSee also setNum()..SH "QString QString::number ( int n, int base = 10 )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSee also setNum()..SH "QString QString::number ( uint n, int base = 10 )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPA convenience factory function that returns a string representation of the number \fIn\fR to the base \fIbase\fR, which is 10 by default and must be between 2 and 36..PPSee also setNum()..SH "QString QString::number ( double n, char f = 'g', int prec = 6 )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPArgument \fIn\fR is formatted according to the \fIf\fR format specified, which is \fCg\fR by default, and can be any of the following:.TP\fCe\fR - format as [-]9.9e[+|-]999.TP\fCE\fR - format as [-]9.9E[+|-]999.TP\fCf\fR - format as [-]9.9.TP\fCg\fR - use \fCe\fR or \fCf\fR format, whichever is the most concise.TP\fCG\fR - use \fCE\fR or \fCf\fR format, whichever is the most concise.PPIn all cases the number of digits after the decimal point is equal to the precision specified in \fIprec\fR..PP.nf.br double d = 12.34;.br QString ds = QString( "'E' format, precision 3, gives %1" ).br .arg( d, 0, 'E', 3 );.br // ds == "1.234E+001".br.fi.PPSee also setNum()..SH "QString::operator const char * () const"Returns latin1(). Be sure to see the warnings documented there. Note that for new code which you wish to be strictly Unicode-clean, you can define the macro QT_NO_ASCII_CAST when compiling your code to hide this function so that automatic casts are not done. This has the added advantage that you catch the programming error described under operator!()..SH "bool QString::operator! () const"Returns TRUE if it is a null string; otherwise FALSE..PP.nf.br QString name = getName();.br if ( !name ).br name = "Rodney";.br.fi.PPNote that if you say.PP.nf.br QString name = getName();.br if ( name ).br doSomethingWith(name);.br.fi.PPIt will call "operator const char*()", which is inefficent; you may wish to define the macro QT_NO_ASCII_CAST when writing code which you wish to remain Unicode-clean..PPWhen you want the above semantics, use:.PP.nf.br QString name = getName();.br if ( !name.isNull() ).br doSomethingWith(name);.br.fi.SH "QString & QString::operator+= ( const QString & str )"Appends \fIstr\fR to the string and returns a reference to the string..SH "QString & QString::operator+= ( QChar c )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAppends \fIc\fR to the string and returns a reference to the string..SH "QString & QString::operator+= ( char c )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAppends \fIc\fR to the string and returns a reference to the string..SH "QString & QString::operator= ( QChar c )"Sets the string to contain just the single character \fIc\fR..SH "QString & QString::operator= ( const QString & s )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAssigns a shallow copy of \fIs\fR to this string and returns a reference to this string. This is very fast because the string isn't actually copied..SH "QString & QString::operator= ( const char * str )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAssigns a deep copy of \fIstr\fR, interpreted as a classic C string to this string and returns a reference to this string..PPIf \fIstr\fR is 0, then a null string is created..PPSee also isNull()..SH "QString & QString::operator= ( const QCString & cs )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAssigns a deep copy of \fIcs\fR, interpreted as a classic C string, to this string and returns a reference to this string..SH "QString & QString::operator= ( char c )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to contain just the single character \fIc\fR..SH "QChar QString::operator[] ( int i ) const"Returns the character at index \fIi\fR, or QChar::null if \fIi\fR is beyond the length of the string..PPIf the QString is not const (i.e., const QString) or const& (i.e., const QString&), then the non-const overload of operator[] will be used instead..SH "QCharRef QString::operator[] ( int i )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThe function returns a reference to the character at index \fIi\fR. The resulting reference can then be assigned to, or used immediately, but it will become invalid once further modifications are made to the original string..PPIf \fIi\fR is beyond the length of the string then the string is expanded with QChar::nulls, so that the QCharRef references a valid (null) character in the string..PPThe QCharRef internal class can be used much like a constant QChar, but if you assign to it, you change the original string (which will detach itself because of QString's copy-on-write semantics). You will get compilation errors if you try to use the result as anything but a QChar..SH "QString & QString::prepend ( const QString & s )"Inserts \fIs\fR at the beginning of the string and returns a reference to the string..PPEquivalent to insert(0, \fIs\fR)..PP.nf.br QString string = "42";.br string.prepend( "The answer is " );.br // string == "The answer is 42".br.fi.PPSee also insert()..SH "QString & QString::prepend ( char ch )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts \fIch\fR at the beginning of the string and returns a reference to the string..PPEquivalent to insert(0, \fIch\fR)..PPSee also insert()..SH "QString & QString::prepend ( QChar ch )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts \fIch\fR at the beginning of the string and returns a reference to the string..PPEquivalent to insert(0, \fIch\fR)..PPSee also insert()..SH "QChar & QString::ref ( uint i )"Returns the QChar at index \fIi\fR by reference, expanding the string with QChar::null if necessary. The resulting reference can be assigned to, or otherwise used immediately, but becomes invalid once furher modifications are made to the string..PP.nf.br QString string("ABCDEF");.br QChar ch = string.ref( 3 ); // ch == 'D'.br.fi.PPSee also constref()..SH "QString & QString::remove ( uint index, uint len )"Removes \fIlen\fR characters starting at position \fIindex\fR from the string and returns a reference to the string..PPIf \fIindex\fR is beyond the length of the string, nothing happens. If \fIindex\fR is within the string, but \fIindex\fR plus \fIlen\fR is beyond the end of the string, the string is truncated at position \fIindex\fR..PP.nf.br
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -