⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qstring.3qt

📁 linux下GUI编程工具qt的在线连接帮助手册
💻 3QT
📖 第 1 页 / 共 5 页
字号:
    QString string( "Montreal" );.br    string.remove( 1, 4 );      // string == "Meal".br.fi.PPSee also insert() and replace()..SH "QString & QString::replace ( uint index, uint len, const QString & s )"Replaces \fIlen\fR characters starting at position \fIindex\fR from the string with \fIs\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 \fIindex\fR is valid, but \fIindex\fR plus \fIlen\fR is beyond the end of the string, the string is truncated at position \fIindex\fR, then \fIs\fR is appended at the end..PP.nf.br    QString string( "Say yes!" );.br    string = string.replace( 4, 3, "NO" );.br    // string == "Say NO!".br.fi.PPSee also insert() and remove()..PPExamples:.)l listviews/listviews.cpp, network/networkprotocol/nntp.cpp and qmag/qmag.cpp..SH "QString & QString::replace ( uint index, uint len, const QChar * s, uint slen )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReplaces \fIlen\fR characters starting at position \fIindex\fR by \fIslen\fR characters of QChar data from \fIs\fR, and returns a reference to the string..PPSee also insert() and remove()..SH "QString & QString::replace ( const QRegExp & rx, const QString & str )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReplaces every occurrence of the regexp \fIrx\fR in the string with \fIstr\fR. Returns a reference to the string..PP.nf.br    QString string = "banana";.br    string = string.replace( QRegExp("an"), "" ); // string == "ba".br.fi.PPSee also find() and findRev()..SH "QString QString::right ( uint len ) const"Returns a string that contains the \fIlen\fR rightmost characters of the string..PPIf \fIlen\fR is greater than the length of the string then the whole string is returned..PP.nf.br    QString string( "Pineapple" );.br    QString t = string.right( 5 );   // t == "apple".br.fi.PPSee also left(), mid() and isEmpty()..PPExample: fileiconview/qfileiconview.cpp..SH "QString QString::rightJustify ( uint width, QChar fill = ' ', bool truncate = FALSE ) const"Returns a string of length \fIwidth\fR that contains the \fIfill\fR character followed by the string..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 the resulting string is truncated at position \fIwidth\fR..PP.nf.br    QString string( "apple" );.br    QString t = string.rightJustify( 8, '.' );  // t == "...apple".br.fi.PPSee also leftJustify()..SH "QString QString::section ( QChar sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const"This function returns a section of the string..PPThis string is treated as a sequence of fields separated by the character, \fIsep\fR. The returned string consists of the fields from position \fIstart\fR to position \fIend\fR inclusive. If \fIend\fR is not specified, all fields from position \fIstart\fR to the end of the string are included..PPThe \fIflags\fR argument can be used to affect some aspects of the function's behaviour, e.g. whether to be case sensitive, whether to skip empty fields and how to deal with leading and trailing separators; see SectionFlags..PP.nf.br    QString csv( "forename,middlename,surname,phone" );.br    QString s = csv.section( ',', 2, 2 );   // s == "surname".br.br    QString path( "/usr/local/bin/myapp" ); // First field is empty.br    QString s = path.section( '/', 3, 4 );  // s == "bin/myapp".br    QString s = path.section( '/', 3, 3, SectionSkipEmpty ); // s == "myapp".br.fi.PPIf \fIstart\fR or \fIend\fR is negative, we count fields from the right of the string, the right-most field being -1, the one from right-most field being -2, and so on..PP.nf.br    QString csv( "forename,middlename,surname,phone" );.br    QString s = csv.section( ',', -3, -2 );  // s == "middlename,surname".br.br    QString path( "/usr/local/bin/myapp" ); // First field is empty.br    QString s = path.section( '/', -1 ); // s == "myapp".br.fi.PPSee also QStringList::split()..SH "QString QString::section ( char sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "QString QString::section ( const char * sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..SH "QString QString::section ( const QString & sep, int start, int end = 0xffffffff, int flags = SectionDefault ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThis function returns a section of the string..PPThis string is treated as a sequence of fields separated by the string, \fIsep\fR. The returned string consists of the fields from position \fIstart\fR to position \fIend\fR inclusive. If \fIend\fR is not specified, all fields from position \fIstart\fR to the end of the string are included..PPThe \fIflags\fR argument can be used to affect some aspects of the function's behaviour, e.g. whether to be case sensitive, whether to skip empty fields and how to deal with leading and trailing separators; see SectionFlags..PP.nf.br    QString data( "forename**middlename**surname**phone" );.br    QString s = data.section( "**", 2, 2 ); // s == "surname".br.fi.PPIf \fIstart\fR or \fIend\fR is negative, we count fields from the right of the string, the right-most field being -1, the one from right-most field being -2, and so on..PP.nf.br    QString data( "forename**middlename**surname**phone" );.br    QString s = data.section( "**", -3, -2 ); // s == "middlename**surname".br.fi.PPSee also QStringList::split()..SH "QString QString::section ( const QRegExp & reg, int start, int end = 0xffffffff, int flags = SectionDefault ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThis function returns a section of the string..PPThis string is treated as a sequence of fields separated by the regular expression, \fIreg\fR. The returned string consists of the fields from position \fIstart\fR to position \fIend\fR inclusive. If \fIend\fR is not specified, all fields from position \fIstart\fR to the end of the string are included..PPThe \fIflags\fR argument can be used to affect some aspects of the function's behaviour, e.g. whether to be case sensitive, whether to skip empty fields and how to deal with leading and trailing separators; see SectionFlags..PP.nf.br    QString line( "forename\\tmiddlename  surname \\t \\t phone" );.br    QRegExp sep( "\\s+" );.br    QString s = line.section( sep, 2, 2 ); // s == "surname".br.fi.PPIf \fIstart\fR or \fIend\fR is negative, we count fields from the right of the string, the right-most field being -1, the one from right-most field being -2, and so on..PP.nf.br    QString line( "forename\\tmiddlename  surname \\t \\t phone" );.br    QRegExp sep( "\\\\s+" );.br    QString s = line.section( sep, -3, -2 ); // s == "middlename  surname".br.fi.PP\fBWarning:\fR Section on QRegExp is much more expensive than the overloaded string and character versions..PPSee also QStringList::split() and simplifyWhiteSpace()..SH "void QString::setExpand ( uint index, QChar c )"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPSets the character at position \fIindex\fR to \fIc\fR and expands the string if necessary, filling with spaces..PPThis method is redundant in Qt 3.x, because operator[] will expand the string as necessary..SH "QString & QString::setLatin1 ( const char * str, int len = -1 )"Sets this string to \fIstr\fR, interpreted as a classic Latin1 C string. If \fIlen\fR is -1 (the default), then it is set to strlen(str)..PPIf \fIstr\fR is 0 a null string is created. If \fIstr\fR is "", an empty string is created..PPSee also isNull() and isEmpty()..SH "void QString::setLength ( uint newLen )"Ensures that at least \fInewLen\fR characters are allocated to the string, and sets the length of the string to \fInewLen\fR. Any new space allocated contains arbitrary data..PPIf \fInewLen\fR is 0, then the string becomes empty, unless the string is null, in which case it remains null..PPThis function always detaches the string from other references to the same data..PPThis function is useful for code that needs to build up a long string and wants to avoid repeated reallocation. In this example, we want to add to the string until some condition is true, and we're fairly sure that size is big enough:.PP.nf.br    QString result;.br    int resultLength = 0;.br    result.setLength( newLen ) // allocate some space.br    while ( ... ) {.br        result[resultLength++] = ... // fill (part of) the space with data.br    }.br    result.truncate[resultLength]; // and get rid of the undefined junk.br.fi.PPIf \fInewLen\fR is an underestimate, the worst that will happen is that the loop will slow down..PPSee also truncate(), isNull(), isEmpty() and length()..SH "QString & QString::setNum ( long n, int base = 10 )"Sets the string to the printed value of \fIn\fR in base \fIbase\fR and returns a reference to the string..PPThe base is 10 by default and must be between 2 and 36..PP.nf.br    QString string;.br    string = string.setNum( 1234 );     // string == "1234".br.fi.SH "QString & QString::setNum ( short n, int base = 10 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to the printed value of \fIn\fR in base \fIbase\fR and returns a reference to the string..PPThe base is 10 by default and must be between 2 and 36..SH "QString & QString::setNum ( ushort n, int base = 10 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to the printed value of \fIn\fR in base \fIbase\fR and returns a reference to the string..PPThe base is 10 by default and must be between 2 and 36..SH "QString & QString::setNum ( int n, int base = 10 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to the printed value of \fIn\fR in base \fIbase\fR and returns a reference to the string..PPThe base is 10 by default and must be between 2 and 36..SH "QString & QString::setNum ( uint n, int base = 10 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to the printed value of \fIn\fR in base \fIbase\fR and returns a reference to the string..PPThe base is 10 by default and must be between 2 and 36..SH "QString & QString::setNum ( ulong n, int base = 10 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to the printed value of \fIn\fR in base \fIbase\fR and returns a reference to the string..PPThe base is 10 by default and must be between 2 and 36..SH "QString & QString::setNum ( float n, char f = 'g', int prec = 6 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to the printed value of \fIn\fR, formatted in format \fIf\fR with precision \fIprec\fR, and returns a reference to the string..PPThe format \fIf\fR can be 'f', 'F', 'e', 'E', 'g' or 'G'. See arg() for an explanation of the formats..SH "QString & QString::setNum ( double n, char f = 'g', int prec = 6 )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPSets the string to the printed value of \fIn\fR, formatted in format \fIf\fR with precision \fIprec\fR, and returns a reference to the string..PPThe format \fIf\fR can be 'f', 'F', 'e', 'E', 'g' or 'G'. See arg() for an explanation of the formats..SH "QString & QString::setUnicode ( const QChar * unicode, uint len )"Resizes the string to \fIlen\fR characters and copies \fIunicode\fR into the string. If \fIunicode\fR is null, nothing is copied, but the string is still resized to \fIlen\fR. If \fIlen\fR is zero, then the string becomes a null string..PPSee also setLatin1() and isNull()..SH "QString & QString::setUnicodeCodes ( const ushort * unicode_as_ushorts, uint len )"Resizes the string to \fIlen\fR characters and copies \fIunicode_as_ushorts\fR into the string (on some X11 client platforms this will involve a byte-swapping pass)..PPIf \fIunicode_as_ushorts\fR is null, nothing is copied, but the string is still resized to \fIlen\fR. If \fIlen\fR is zero, the string becomes a null string..PPSee also setLatin1() and isNull()..SH "QString QString::simplifyWhiteSpace () const"Returns a string that has whitespace removed from the start and the end of the string, and any sequence of internal whitespace is replaced with a single space..PPWhitespace means any character for which QChar::isSpace() returns TRUE. This includes UNICODE characters with decimal values 9 (TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR), and 32 (Space)..PP.nf.br    QString string = "  lots\\t of\\nwhite    space ";.br    QString t = string.simplifyWhiteSpace();.br    // t == "lots of white space".br.fi.PPSee also stripWhiteSpace()..SH "QString & QString::sprintf ( const char * cformat, ... )"Safely builds a formatted string from the format string \fIcformat\fR and an arbitrary list of arguments. The format string supports all the escape sequences of printf() in the standard C library..PPThe %s escape sequence expects a utf8() encoded string. The format string \fIcformat\fR is expected to be in latin1. If you need a unicode format string, use arg() instead. For typesafe string building, with full Unicode support, you can use QTextOStream like this:.PP.nf.br    QString str;.br    QString s = ...;.br    int x = ...;.br    QTextOStream( &str ) << s << " : " << x;.br.fi.PPFor translations, especially if the strings contains more than one escape sequence, you should consider using the arg() function instead. This allows the order of the replacements to be controlled by the translator, and has Unicode support..PPSee also arg()..PPExamples:.)l dclock/dclock.cpp, forever/forever.cpp, layout/layout.cpp, qmag/qmag.cpp, scrollview/scrollview.cpp, tooltip/tooltip.cpp and xform/xform.cpp..SH "bool QString::startsWith ( const QString & s ) const"Returns TRUE if the string starts with \fIs\fR; otherwise it returns FALSE..PP.nf.br    QString string("Bananas");.br    bool a = string.startsWi

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -