📄 qstring.3qt
字号:
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, bool cs = TRUE ) const"Returns TRUE if the string ends with \fIs\fR; otherwise returns FALSE..PPIf \fIcs\fR is TRUE (the default), the search is case sensitive; otherwise the search is case insensitive..PP.nf.br QString str( "Bananas" );.br str.endsWith( "anas" ); // returns TRUE.br str.endsWith( "pple" ); // returns FALSE.br.fi.PPSee also startsWith()..PPExample: chart/main.cpp..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 == "ggggg".br.fi.SH "int QString::find ( const QRegExp & rx, int index = 0 ) const"Finds the first match of the regular expression \fIrx\fR, starting from 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 match of \fIrx\fR or -1 if no match was 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 (the default), the search is case sensitive; otherwise 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..PPIf \fIcs\fR is TRUE (the default), the search is case sensitive; otherwise the search 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.).PPIf \fIcs\fR is TRUE (the default), the search is case sensitive; otherwise the search is case insensitive..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 (the default), the search is case sensitive; otherwise 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..PPIf \fIcs\fR is TRUE (the default), the search is case sensitive; otherwise the search 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 (the default), the search is case sensitive; otherwise 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 match 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 the match or -1 if no match was found..PP.nf.br QString string( "bananas" );.br int i = string.findRev( QRegExp("an") ); // i == 3.br.fi.PPSee also find()..SH "QString QString::fromAscii ( const char * ascii, int len = -1 )\fC [static]\fR"Returns the Unicode string decoded from the first \fIlen\fR bytes of \fIascii\fR, ignoring the rest of \fIascii\fR. If \fIlen\fR is -1 then the length of \fIascii\fR is used. If \fIlen\fR is bigger than the length of \fIascii\fR then it will use the length of \fIascii\fR..PPIf a codec has been set using QTextCodec::codecForCStrings(), it is used to convert the string from 8-bit characters to Unicode. Otherwise, this function does the same as fromLatin1()..PPThis is the same as the QString(const char*) constructor, but you can make that constructor invisible if you compile with the define \fCQT_NO_CAST_ASCII\fR, in which case you can explicitly create a QString from 8-bit ASCII text using this function..PP.nf.br QString str = QString::fromAscii( "123456789", 5 );.br // str == "12345".br.fi.SH "QString QString::fromLatin1 ( const char * chars, int len = -1 )\fC [static]\fR"Returns the Unicode string decoded from the first \fIlen\fR bytes 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..PPSee also fromAscii()..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 bytes 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::fromUcs2 ( const unsigned short * str )\fC [static]\fR"Constructs a string that is a deep copy of \fIstr\fR, interpreted as a UCS2 encoded, zero terminated, Unicode string..PPIf \fIstr\fR is 0, then a null string is created..PPSee also isNull()..SH "QString QString::fromUtf8 ( const char * utf8, int len = -1 )\fC [static]\fR"Returns the Unicode string decoded from the first \fIlen\fR bytes 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 at 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()..PPExamples:.)l themes/themes.cpp and xform/xform.cpp..SH "QString & QString::insert ( uint index, const QByteArray & s )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts \fIs\fR into the string at position \fIindex\fR and returns a reference to the string..SH "QString & QString::insert ( uint index, const char * s )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPInserts \fIs\fR into the string at position \fIindex\fR and returns a reference to the string..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 first \fIlen\fR characters in \fIs\fR into the string at position \fIindex\fR 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 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; otherwise returns FALSE. Null strings are also empty..PP.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, chart/chartform.cpp, chart/chartform_canvas.cpp, network/networkprotocol/nntp.cpp, qmag/qmag.cpp, and qwerty/qwerty.cpp..SH "bool QString::isNull () const"Returns TRUE if the string is null; otherwise returns FALSE. 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, because a.length() == 0.br.fi.PPSee also isEmpty() and length()..PPExamples:.)l i18n/main.cpp, network/ftpclient/ftpmainwindow.ui.h, and qdir/qdir.cpp..SH "const char * QString::latin1 () const"Returns a Latin-1 representation of the string. 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 fromLatin1(), ascii(), 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()..PPExample: themes/themes.cpp..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 dirview/dirview.cpp, fileiconview/qfileiconview.cpp, network/networkprotocol/nntp.cpp, rot13/rot13.cpp, and themes/themes.cpp.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -