📄 qstring.3qt
字号:
.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. On Mac OS X, this always uses UTF-8 as the encoding..PPSee QTextCodec for more diverse coding/decoding of Unicode strings..PPSee also fromLocal8Bit(), ascii(), 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..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 lowercase copy of the string..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\fR + \fIlen\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, qmag/qmag.cpp, and themes/themes.cpp..SH "QString QString::number ( long n, int base = 10 )\fC [static]\fR"A convenience function that returns a string equivalent 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 application/application.cpp, chart/chartform.cpp, fonts/simple-qfont-demo/viewer.cpp, helpviewer/helpwindow.cpp, mdi/application.cpp, regexptester/regexptester.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 ( Q_LLONG 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 ( Q_ULLONG 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:.PP<center>.nf.TSl - l. Format Meaning format as [-]9.9e[+|-]999 format as [-]9.9E[+|-]999 format as [-]9.9 use use.TE.fi</center>.PPWith 'e', 'E', and 'f', \fIprec\fR is the number of digits after the decimal point. With 'g' and 'G', \fIprec\fR is the maximum number of significant digits (trailing zeroes are omitted)..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 ascii(). Be sure to see the warnings documented in the ascii() function. Note that for new code which you wish to be strictly Unicode-clean, you can define the macro \fCQT_NO_ASCII_CAST\fR 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 in operator!()..SH "QString::operator std::string () const"Returns ascii() as a std::string..SH "bool QString::operator! () const"Returns TRUE if this is a null string; otherwise returns 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 \fCQT_NO_ASCII_CAST\fR 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.PPSee also isEmpty()..SH "QString & QString::operator+= ( const QString & str )"Appends \fIstr\fR to the string and returns a reference to the string..SH "QString & QString::operator+= ( const QByteArray & str )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAppends \fIstr\fR to the string and returns a reference to the string..SH "QString & QString::operator+= ( const char * str )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAppends \fIstr\fR to the string and returns a reference to the string..SH "QString & QString::operator+= ( const std::string & str )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAppends \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 std::string & s )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPMakes a deep copy of \fIs\fR and returns a reference to the deep copy..SH "QString & QString::operator= ( const QCString & cstr )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPAssigns a deep copy of \fIcstr\fR, interpreted as a classic C string, to this string. 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 "QString & QString::prepend ( const QByteArray & s )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts \fIs\fR at the beginning of the string and returns a reference to the string..PPEquivalent to insert(0, \fIs\fR)..PPSee also insert()..SH "QString & QString::prepend ( const char * s )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts \fIs\fR at the beginning of the string and returns a reference to the string..PPEquivalent to insert(0, \fIs\fR)..PPSee also insert()..SH "QString & QString::prepend ( const std::string & s )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts \fIs\fR at the beginning of the string and returns a reference to the string..PPEquivalent to insert(0, \fIs\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 from the string starting at position \fIindex\fR, 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 + \fIlen\fR is beyond the end of the string, the string is truncated at position \fIindex\fR..PP.nf.br QString string( "Montreal" );.br string.remove( 1, 4 ); // string == "Meal".br.fi.PPSee also insert() and replace()..SH "QString & QString::remove ( const QString & str, bool cs = TRUE )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPRemoves every occurrence of \fIstr\fR in the string. Returns a reference to the string..PPIf \fIcs\fR is TRUE (the default), the search is case sensitive; otherwise the search is case insensitive..PPThis is the same as replace(\fIstr\fR, "", \fIcs\fR)..SH "QString & QString::remove ( QChar c )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPRemoves every occurrence of the character \fIc\fR in the string. Returns a reference to the string..PPThis is the same as replace(\fIc\fR, "")..SH "QString & QString::remove ( char c )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPRemoves every occurrence of the character \fIc\fR in the string. Returns a reference to the string..PPThis is the same as replace(\fIc\fR, "")..SH "QString & QString::remove ( const char * str )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPRemoves every occurrence of \fIstr\fR in the string. Returns a reference to the string..SH "QString & QString::remove ( const QRegExp & rx )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPRemoves every occurrence of the regular expression \fIrx\fR in the string. Returns a reference to the string..PPThis is the same as replace(\fIrx\fR, "")..SH "QString & QString::replace ( uint index, uint len, const QString & s )"Replaces \fIlen\fR characters from the string with \fIs\fR, starting at position \fIindex\fR, and returns a reference to the string..PPIf \fIindex\fR is beyond the length of the string, nothing is deleted and \fIs\fR is appended at the end of the string. If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -