📄 qstring.3qt
字号:
Argument \fIa\fR is formatted according to the \fIfmt\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.SH "const char * QString::ascii () const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPThis function simply calls latin1() and returns the result..PPExample: network/networkprotocol/nntp.cpp..SH "QChar QString::at ( uint i ) const"Returns the character at index \fIi\fR, or 0 if \fIi\fR is beyond the length of the string..PP.nf.br const QString string( "abcdefgh" );.br QChar ch = string.at( 4 );.br // ch == 'e'.br.fi.PPIf the QString is not const (i.e. const QString) or const& (i.e. const QString &), then the non-const overload of at() will be used instead..SH "QCharRef QString::at ( uint 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::null..SH "int QString::compare ( const QString & s1, const QString & s2 )\fC [static]\fR"Lexically 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 based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with QString::localeAwareCompare()..PP.nf.br int a = QString::compare( "def", "abc" ); // a > 0.br int b = QString::compare( "abc", "def" ); // b < 0.br int c = QString::compare(" abc", "abc" ); // c == 0.br.fi.SH "int QString::compare ( const QString & s ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPLexically compares this string with \fIs\fR and returns an integer less than, equal to, or greater than zero if it is less than, equal to, or greater than \fIs\fR..SH "void QString::compose ()"Note that this function is not supported in Qt 3.0 and is merely for experimental and illustrative purposes. It is mainly of interest to those experimenting with Arabic and other composition-rich texts..PPApplies possible ligatures to a QString. Useful when composition-rich text requires rendering with glyph-poor fonts, but it also makes compositions such as QChar(0x0041) ('A') and QChar(0x0308) (Unicode accent diaresis), giving QChar(0x00c4) (German A Umlaut)..SH "QChar QString::constref ( uint i ) const"Returns the QChar at index \fIi\fR by value..PPEquivalent to at(\fIi\fR)..PPSee also ref()..SH "int QString::contains ( QChar c, bool cs = TRUE ) const"Returns the number of times the character \fIc\fR occurs in the string..PPIf \fIcs\fR is TRUE then the match is case sensitive. If \fIcs\fR is FALSE, then the match is case insensitive..PP.nf.br QString string( "Trolltech and Qt" );.br int i = string.contains( 't', FALSE ); // i == 3.br.fi.PPExamples:.)l fileiconview/qfileiconview.cpp and mdi/application.cpp..SH "int QString::contains ( char c, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "int QString::contains ( const char * str, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the number of times the string \fIstr\fR occurs in the string..PPIf \fIcs\fR is TRUE then the match is case sensitive. If \fIcs\fR is FALSE, then the match is case insensitive..SH "int QString::contains ( const QString & str, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the number of times \fIstr\fR occurs in the string..PPThe match is case sensitive if \fIcs\fR is TRUE or case insensitive if \fIcs\fR if FALSE..PPThis function counts overlapping strings, so in the example below, there are two instances of "ana" in "bananas"..PP.nf.br QString str( "bananas" );.br int i = str.contains( "ana" ); // i == 2.br.fi.PPSee also findRev()..SH "int QString::contains ( const QRegExp & rx ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns the number of times the regexp, \fIrx\fR, occurs in the string..PPThis function counts overlapping occurrences, so in the example below, there are four instances of "ana" or "ama"..PP.nf.br QString str = "banana and panama";.br QRegExp rxp = QRegExp( "a[nm]a", TRUE, FALSE );.br int i = str.contains( rxp ); // i == 4.br.fi.PPSee also find() and findRev()..SH "QString QString::copy () const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPIn Qt 2.0 and later, all calls to this function are needless. Just remove them..SH "const char * QString::data () const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPReturns a pointer to a 0-terminated classic C string..PPIn Qt 1.x, this returned a char* allowing direct manipulation of the string as a sequence of bytes. In Qt 2.x where QString is a Unicode string, char* conversion constructs a temporary string, and hence direct character operations are meaningless..SH "bool QString::endsWith ( const QString & s ) const"Returns TRUE if the string ends with \fIs\fR; otherwise it returns FALSE..PPSee also startsWith()..SH "QString & QString::fill ( QChar c, int len = -1 )"Fills the string with \fIlen\fR characters of value \fIc\fR, and returns a reference to the string..PPIf \fIlen\fR is negative (the default), the current string length is used..PP.nf.br QString str;.br str.fill( 'g', 5 ); // string == "gggggg".br.fi.SH "int QString::find ( const QRegExp & rx, int index = 0 ) const"Finds the first occurrence of the constant regular expression \fIrx\fR, starting at position \fIindex\fR. If \fIindex\fR is -1, the search starts at the last character; if -2, at the next to last character and so on. (See findRev() for searching backwards.).PPReturns the position of the first occurrence of \fIrx\fR or -1 if \fIrx\fR was not found..PP.nf.br QString string( "bananas" );.br int i = string.find( QRegExp("an"), 0 ); // i == 1.br.fi.PPSee also findRev(), replace() and contains()..PPExample: network/mail/smtp.cpp..SH "int QString::find ( QChar c, int index = 0, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFinds the first occurrence of the character \fIc\fR, starting at position \fIindex\fR. If \fIindex\fR is -1, the search starts at the last character; if -2, at the next to last character and so on. (See findRev() for searching backwards.).PPIf \fIcs\fR is TRUE, then the search is case sensitive. If \fIcs\fR is FALSE, then the search is case insensitive..PPReturns the position of \fIc\fR or -1 if \fIc\fR could not be found..SH "int QString::find ( char c, int index = 0, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFind character \fIc\fR starting from position \fIindex\fR. If \fIcs\fR is TRUE then the match is case sensitive. If \fIcs\fR is FALSE, then the match is case insensitive..SH "int QString::find ( const QString & str, int index = 0, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFinds the first occurrence of the string \fIstr\fR, starting at position \fIindex\fR. If \fIindex\fR is -1, the search starts at the last character, if it is -2, at the next to last character and so on. (See findRev() for searching backwards.).PPThe search is case sensitive if \fIcs\fR is TRUE or case insensitive if \fIcs\fR is FALSE..PPReturns the position of \fIstr\fR or -1 if \fIstr\fR could not be found..SH "int QString::find ( const char * str, int index = 0 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPEquivalent to find(QString(\fIstr\fR), \fIindex\fR)..SH "int QString::findRev ( const char * str, int index = -1 ) const"Equivalent to findRev(QString(\fIstr\fR), \fIindex\fR)..SH "int QString::findRev ( QChar c, int index = -1, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFinds the first occurrence of the character \fIc\fR, starting at position \fIindex\fR and searching backwards. If the index is -1, the search starts at the last character, if it is -2, at the next to last character and so on..PPReturns the position of \fIc\fR or -1 if \fIc\fR could not be found..PPIf \fIcs\fR is TRUE then the search is case sensitive. If \fIcs\fR is FALSE then the search is case insensitive..PP.nf.br QString string( "bananas" );.br int i = string.findRev( 'a' ); // i == 5.br.fi.SH "int QString::findRev ( char c, int index = -1, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFind character \fIc\fR starting from position \fIindex\fR and working backwards. If \fIcs\fR is TRUE then the match is case sensitive. If \fIcs\fR is FALSE, then the match is case insensitive..SH "int QString::findRev ( const QString & str, int index = -1, bool cs = TRUE ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFinds the first occurrence of the string \fIstr\fR, starting at position \fIindex\fR and searching backwards. If the index is -1, the search starts at the last character, if it is -2, at the next to last character and so on..PPReturns the position of \fIstr\fR or -1 if \fIstr\fR could not be found..PPIf \fIcs\fR is TRUE then the search is case sensitive. If \fIcs\fR is FALSE then the search is case insensitive..PP.nf.br QString string("bananas");.br int i = string.findRev( "ana" ); // i == 3.br.fi.SH "int QString::findRev ( const QRegExp & rx, int index = -1 ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPFinds the first occurrence of the regexp \fIrx\fR, starting at position \fIindex\fR and searching backwards. If the index is -1, the search starts at the last character, if it is -2, at the next to last character and so on. (See findRev() for searching backwards.).PPReturns the position of \fIrx\fR or -1 if \fIrx\fR could not be found..PP.nf.br QString string( "bananas" );.br int i = string.findRev( QRegExp("an") ); // i == 3.br.fi.PPSee also find()..SH "QString QString::fromLatin1 ( const char * chars, int len = -1 )\fC [static]\fR"Returns the unicode string decoded from the first \fIlen\fR characters of \fIchars\fR, ignoring the rest of \fIchars\fR. If \fIlen\fR is -1 then the length of \fIchars\fR is used. If \fIlen\fR is bigger than the length of \fIchars\fR then it will use the length of \fIchars\fR..PPThis is the same as the QString(const char*) constructor, but you can make that constructor invisible if you compile with the define QT_NO_CAST_ASCII, in which case you can explicitly create a QString from Latin-1 text using this function..PP.nf.br QString str = QString::fromLatin1( "123456789", 5 );.br // str == "12345".br.fi.PPExamples:.)l listbox/listbox.cpp and network/mail/smtp.cpp..SH "QString QString::fromLocal8Bit ( const char * local8Bit, int len = -1 )\fC [static]\fR"Returns the unicode string decoded from the first \fIlen\fR characters of \fIlocal8Bit\fR, ignoring the rest of \fIlocal8Bit\fR. If \fIlen\fR is -1 then the length of \fIlocal8Bit\fR is used. If \fIlen\fR is bigger than the length of \fIlocal8Bit\fR then it will use the length of \fIlocal8Bit\fR..PP.nf.br QString str = QString::fromLocal8Bit( "123456789", 5 );.br // str == "12345".br.fi.PP\fIlocal8Bit\fR is assumed to be encoded in a locale-specific format..PPSee QTextCodec for more diverse coding/decoding of Unicode strings..SH "QString QString::fromUtf8 ( const char * utf8, int len = -1 )\fC [static]\fR"Returns the unicode string decoded from the first \fIlen\fR characters of \fIutf8\fR, ignoring the rest of \fIutf8\fR. If \fIlen\fR is -1 then the length of \fIutf8\fR is used. If \fIlen\fR is bigger than the length of \fIutf8\fR then it will use the length of \fIutf8\fR..PP.nf.br QString str = QString::fromUtf8( "123456789", 5 );.br // str == "12345".br.fi.PPSee QTextCodec for more diverse coding/decoding of Unicode strings..PPExample: fonts/simple-qfont-demo/viewer.cpp..SH "QString & QString::insert ( uint index, const QString & s )"Inserts \fIs\fR into the string before position \fIindex\fR..PPIf \fIindex\fR is beyond the end of the string, the string is extended with spaces to length \fIindex\fR and \fIs\fR is then appended and returns a reference to the string..PP.nf.br QString string( "I like fish" );.br str = string.insert( 2, "don't " );.br // str == "I don't like fish".br.fi.PPSee also remove() and replace()..PPExample: xform/xform.cpp..SH "QString & QString::insert ( uint index, const QChar * s, uint len )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts the character in \fIs\fR into the string before the position \fIindex\fR \fIlen\fR number of times and returns a reference to the string..SH "QString & QString::insert ( uint index, QChar c )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInsert \fIc\fR into the string at (before) position \fIindex\fR and returns a reference to the string..PPIf \fIindex\fR is beyond the end of the string, the string is extended with spaces (ASCII 32) to length \fIindex\fR and \fIc\fR is then appended..SH "QString & QString::insert ( uint index, char c )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInsert character \fIc\fR at position \fIindex\fR..SH "bool QString::isEmpty () const"Returns TRUE if the string is empty, i.e., if length() == 0. Thus, null strings are empty strings..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -