📄 qstring.3qt
字号:
.BI "operator \fBconst char*\fR ()const".br.ti -1c.BI "QString& \fBsetUnicode\fR ( const QChar * " "unicode" ", uint len ) ".br.ti -1c.BI "QString& \fBsetUnicodeCodes\fR ( const ushort * " "unicode_as_ushorts" ", uint len ) ".br.ti -1c.BI "QString& \fBsetLatin1\fR ( const char *, int " "len" "=-1 ) ".br.ti -1c.BI "int \fBcompare\fR ( const QString & s ) const".br.ti -1c.BI "void \fBcompose\fR () ".br.ti -1c.BI "QChar::Direction \fBbasicDirection\fR () ".br.ti -1c.BI "QString \fBvisual\fR ( int " "index" " = 0, int " "len" " = -1 ) ".br.ti -1c.BI "bool \fBstartsWith\fR ( const QString & ) const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "QString \fBnumber\fR ( long, int " "base" "=10 ) ".br.ti -1c.BI "QString \fBnumber\fR ( ulong, int " "base" "=10 ) ".br.ti -1c.BI "QString \fBnumber\fR ( int, int " "base" "=10 ) ".br.ti -1c.BI "QString \fBnumber\fR ( uint, int " "base" "=10 ) ".br.ti -1c.BI "QString \fBnumber\fR ( double, char " "f" "='g', int " "prec" "=6 ) ".br.ti -1c.BI "QString \fBfromLatin1\fR ( const char *, int " "len" "=-1 ) ".br.ti -1c.BI "QString \fBfromUtf8\fR ( const char *, int " "len" "=-1 ) ".br.ti -1c.BI "QString \fBfromLocal8Bit\fR ( const char *, int " "len" "=-1 ) ".br.ti -1c.BI "int \fBcompare\fR ( const QString & " "s1" ", const QString & s2 ) ".br.in -1c.SH RELATED FUNCTION DOCUMENTATION(Note that these are not member functions.).in +1c.ti -1c.BI "QDataStream & \fBoperator>>\fR (QDataStream & " "s" ", QString & " "str" ")".br.ti -1c.BI "QString \fBoperator+\fR (const char * " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "bool \fBoperator<=\fR (const char * " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "QString \fBoperator+\fR (const QString & " "s1" ", const char * " "s2" ")".br.ti -1c.BI "QString \fBoperator+\fR (const QString & " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "QDataStream & \fBoperator<<\fR (QDataStream & " "s" ", const QString & " "str" ")".br.ti -1c.BI "bool \fBoperator==\fR (const QString & " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "bool \fBoperator!=\fR (const QString & " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "bool \fBoperator!=\fR (const QString & " "s1" ", const char * " "s2" ")".br.ti -1c.BI "bool \fBoperator<\fR (const char * " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "bool \fBoperator>=\fR (const char * " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "QString \fBoperator+\fR (char " "c" ", const QString & " "s" ")".br.ti -1c.BI "bool \fBoperator<=\fR (const QString & " "s1" ", const char * " "s2" ")".br.ti -1c.BI "QString \fBoperator+\fR (const QString & " "s" ", char " "c" ")".br.ti -1c.BI "bool \fBoperator>\fR (const char * " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "bool \fBoperator<\fR (const QString & " "s1" ", const char * " "s2" ")".br.ti -1c.BI "bool \fBoperator!=\fR (const char * " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "bool \fBoperator==\fR (const QString & " "s1" ", const char * " "s2" ")".br.ti -1c.BI "bool \fBoperator==\fR (const char * " "s1" ", const QString & " "s2" ")".br.ti -1c.BI "bool \fBoperator>\fR (const QString & " "s1" ", const char * " "s2" ")".br.ti -1c.BI "bool \fBoperator>=\fR (const QString & " "s1" ", const char * " "s2" ")".br.in -1c.SH DESCRIPTIONThe QString class provides an abstraction of Unicode text and the classic C null-terminated char array (\fIchar*\fR)..PPQString uses implicit sharing, and so it is very efficient and easy to use..PPIn all QString methods that take \fIconst char*\fR parameters, the \fIconst char*\fR is interpreted as a classic C-style 0-terminated ASCII string. It is legal for the \fIconst char*\fR parameter to be 0. The results are undefined if the \fIconst char*\fR string is not 0-terminated. Functions that copy classic C strings into a QString will not copy the terminating 0-character. The QChar array of the QString (as returned by unicode()) is not terminated by a null..PPA QString that has not been assigned to anything is \fInull,\fR i.e. both the length and data pointer is 0. A QString that references the empty string ("", a single '\\0' char) is \fIempty.\fR Both null and empty QStrings are legal parameters to the methods. Assigning \fIconst char * 0\fR to QString gives a null QString..PPNote that if you find that you are mixing usage of QCString, QString, and QByteArray, this causes lots of unnecessary copying and might indicate that the true nature of the data you are dealing with is uncertain. If the data is NUL-terminated 8-bit data, use QCString; if it is unterminated (ie. contains NULs) 8-bit data, use QByteArray; if it is text, use QString..PPSee also QChar and Shared classes.PPExamples:.(lshowimg/main.cpp grapher/grapher.cpp xform/xform.cpp layout/layout.cpp helpviewer/main.cpp life/main.cpp i18n/main.cpp drawdemo/drawdemo.cpp popup/popup.cpp menu/menu.cpp progress/progress.cpp qmag/qmag.cpp forever/forever.cpp rot13/rot13.cpp desktop/desktop.cpp scrollview/scrollview.cpp movies/main.cpp picture/picture.cpp hello/main.cpp.)l.SH MEMBER FUNCTION DOCUMENTATION.SH "QString::QString ()"Constructs a null string..PPSee also isNull()..SH "QString::QString ( QChar ch )"Constructs a string containing the one character \fIch.\fR.SH "QString::QString ( const QByteArray & ba )"Constructs a string that is a deep copy of \fIba\fR interpreted as a classic C string..SH "QString::QString ( const QChar * unicode, uint length )"Constructs a string that is a deep copy of the first \fIlength\fR QChar in the array \fIunicode.\fR.PPIf \fIunicode\fR and \fIlength\fR are 0, a null string is created..PPIf only \fIunicode\fR is 0, the string is empty, but has \fIlength\fR characters of space preallocated - QString expands automatically anyway, but this may speed some cases up a little..PPSee also isNull()..SH "QString::QString ( const QString & s )"Constructs an implicitly-shared copy of \fIs.\fR.SH "QString::QString ( const char * str )"Constructs a string that is a deep copy of \fIstr,\fR interpreted as a classic C string..PPIf \fIstr\fR is 0 a null string is created..PPThis is a cast constructor, but it is perfectly safe: converting a Latin1 const char* to QString preserves all the information. You can disable this constructor by defining QT_NO_CAST_ASCII when you compile your applications. You can also make QString objects by using setLatin1()/fromLatin1(), or fromLocal8Bit(), fromUtf8(), or whatever encoding is appropriate for the 8-bit data you have..PPSee also isNull()..SH "QString::~QString ()"Destroys the string and frees the "real" string, if this was the last copy of that string..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 "QString& QString::append ( QChar ch )"Appends \fIch\fR to the string and returns a reference to the result. Equivalent to operator+=()..SH "QString& QString::append ( char ch )"Appends \fIch\fR to the string and returns a reference to the result. Equivalent to operator+=()..SH "QString& QString::append ( const QString & str )"Appends \fIstr\fR to the string and returns a reference to the result. Equivalent to operator+=()..SH "QString QString::arg ( const QString & a, int fieldwidth=0 ) const"Returns a string equal to this one, but with the lowest-numbered occurrence of \fC%i\fR (for a positive integer i) replaced by \fIa.\fR.PP.nf.br label.setText( tr("Rename %1 to %2?").arg(oldName).arg(newName) );.fi.PP\fIfieldwidth\fR is the minimum amount of space \fIa\fR is padded to. A positive value produces right-aligned text, while a negative value produces left aligned text..PP\fBWarning:\fR Using arg() for constructing "real" sentences programmatically is likely to lead to translation problems. Inserting objects like numbers or file names is fairly safe..PP\fBWarning:\fR Relying on spaces to create alignment is prone to lead to translation problems..PPIf there is no \fC%i\fR pattern, a warning message (qWarning()) is printed and the text as appended at the end of the string. This is error recovery and should not occur in correct code..PPSee also QObject::tr()..SH "QString QString::arg ( QChar a, int fieldwidth=0 ) const"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::arg ( char a, int fieldwidth=0 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIa\fR is assumed to be in the Latin1 character set..SH "QString QString::arg ( double a, int fieldwidth=0, char fmt='g', int prec=-1 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIis\fR formatted according to the \fIfmt\fR format specified, which is 'g' by default and can be any of 'f', 'F', 'e', 'E', 'g' or 'G', all of which have the same meaning as for sprintf(). \fIprec\fR determines the precision, just as for number() and sprintf()..SH "QString QString::arg ( int a, int fieldwidth=0, int base=10 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIa\fR is expressed in to \fIbase\fR notation, which is decimal by default and must be in the range 2-36 inclusive..SH "QString QString::arg ( long a, int fieldwidth=0, int base=10 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIa\fR is expressed in to \fIbase\fR notation, which is decimal by default and must be in the range 2-36 inclusive..SH "QString QString::arg ( short a, int fieldwidth=0, int base=10 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIa\fR is expressed in to \fIbase\fR notation, which is decimal by default and must be in the range 2-36 inclusive..SH "QString QString::arg ( uint a, int fieldwidth=0, int base=10 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIa\fR is expressed in to \fIbase\fR notation, which is decimal by default and must be in the range 2-36 inclusive..SH "QString QString::arg ( ulong a, int fieldwidth=0, int base=10 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIa\fR is expressed in to \fIbase\fR notation, which is decimal by default and must be in the range 2-36 inclusive..SH "QString QString::arg ( ushort a, int fieldwidth=0, int base=10 ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PP\fIa\fR is expressed in to \fIbase\fR notation, which is decimal by default and must be in the range 2-36 inclusive..SH "const char* QString::ascii () const"\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..PPThis functions simply calls latin1() and returns the result..SH "QChar QString::at ( uint ) const"Returns the character at \fIi,\fR or 0 if \fIi\fR is beyond the length of the string..PPNote: If this QString is not const or const&, the non-const at() will be used instead, which will expand the string if \fIi\fR is beyond the length of the string..SH "QCharRef QString::at ( uint i )"Returns a reference to the character at \fIi,\fR expanding the string with QChar::null if necessary. The resulting reference can then be assigned to, or otherwise used immediately, but becomes invalid once further modifications are made to the string..SH "QChar::Direction QString::basicDirection()"This function returns the basic directionality of the string (QChar::DirR for right to left and QChar::DirL for left to right). Useful to find the right alignment..SH "int QString::compare ( const QString & s ) const"Compares this string to \fIs,\fR returning an integer less than, equal to, or greater than zero if it is, respectively, lexically less than, equal to, or greater than \fIs.\fR.SH "int QString::compare ( const QString & s1, const QString & s2 ) \fC[static]\fR"Compare \fIs1\fR to \fIs2\fR returning an integer less than, equal to, or greater than zero if s1 is, respectively, lexically less than, equal to, or greater than s2..SH "void QString::compose ()"Note that this function is not supported in Qt 2.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 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"Equivalent to at(i), this returns the QChar at \fIi\fR by value..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..PPThe match is case sensitive if \fIcs\fR is TRUE, or case insensitive if \fIcs\fR is FALSE..SH "int QString::contains ( const QRegExp & rx ) const"Counts the number of overlapping occurrences of \fIrx\fR in the string..PPExample:.PP.nf.br QString s = "banana and panama";.br QRegExp r = QRegExp("a[nm]a", TRUE, FALSE);.br s.contains( r ); // 4 matches.fi.PPSee also find() and findRev()..SH "int QString::contains ( const QString & str, bool cs=TRUE ) const"Returns 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 is FALSE..PPThis function counts overlapping substrings, for example, "banana" contains two occurrences of "ana"..PPSee also findRev()..SH "int QString::contains ( char c, bool cs=TRUE ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "int QString::contains ( const char * str, bool cs=TRUE ) const"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::copy () const"\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..PPReturns a deep copy of this string..PPDoing this is redundant in Qt 2.x, since QString is implicitly shared, and so will automatically be deeply copied as necessary..SH "void QString::fill ( QChar c, int len = -1 )"Fills the string with \fIlen\fR characters of value \fIc.\fR.PPIf \fIlen\fR is negative, the current string length is used..SH "int QString::find ( QChar c, int index=0, bool cs=TRUE ) const"Finds 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; etc..PPThe search is case sensitive if \fIcs\fR is TRUE, or case insensitive if \fIcs\fR is FALSE..PPReturns the position of \fIc,\fR or -1 if \fIc\fR could not be found..SH "int QString::find ( const QRegExp & rx, int index=0 ) const"Finds the first occurrence of the 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; etc..PPReturns the position of the next match, or -1 if \fIrx\fR was not found..PPSee also findRev(), replace() and contains()..SH "int QString::find ( const QString & str, int index=0, bool cs=TRUE ) const"Finds 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 -2, at the next to last character; etc..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"Equivalent to find(QString(str), index)..SH "int QString::find ( char c, int index=0, bool cs=TRUE ) const"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -