?? qstring.html
字號:
這是一個重載成員函數,提供了方便。它的行為基本上和上面的函數相同。
<p> 把<em>c</em>插入到字符串的<em>index</em>位置之前并且返回這個字符串的引用。
<p> 如果<em>index</em>超過字符串的結尾,字符串被填充空格(ASCII碼為32)擴展到<em>index</em>長度并且然后<em>s</em>被添加,返回這個字符串的引用。
<h3 class=fn><a href="qstring.html">QString</a> & <a name="insert-4"></a>QString::insert ( uint index, char c )
</h3>
這是一個重載成員函數,提供了方便。它的行為基本上和上面的函數相同。
<p> 在<em>index</em>位置插入字符<em>c</em>。
<h3 class=fn>bool <a name="isEmpty"></a>QString::isEmpty () const
</h3>
<p> 如果字符串為空,也就是如果<a href="#length">length</a>() == 0,返回真。因此,零字符串也是空字符串。
<p> <pre>
QString a( "" );
a.<a href="#isEmpty">isEmpty</a>(); // 真
a.<a href="#isNull">isNull</a>(); // 假
QString b;
b.<a href="#isEmpty">isEmpty</a>(); // 真
b.<a href="#isNull">isNull</a>(); // 真
</pre>
<p> <p>也可以參考<a href="#isNull">isNull</a>()和<a href="#length">length</a>()。
<p>實例:<a href="addressbook-example.html#x520">addressbook/mainwindow.cpp</a>、<a href="canvas-chart-example.html#x2611">chart/chartform.cpp</a>、<a href="tutorial2-06.html#x2481">chart/chartform_canvas.cpp</a>、<a href="networkprotocol-example.html#x620">network/networkprotocol/nntp.cpp</a>、<a href="qmag-example.html#x1645">qmag/qmag.cpp</a>和<a href="qwerty-example.html#x388">qwerty/qwerty.cpp</a>。
<h3 class=fn>bool <a name="isNull"></a>QString::isNull () const
</h3>
<p> 如果字符串為零,返回真。零字符串總是空的。
<p> <pre>
QString a; // a.<a href="#unicode">unicode</a>() == 0,a.<a href="#length">length</a>() == 0
a.<a href="#isNull">isNull</a>(); // 真,因為a.<a href="#unicode">unicode</a>() == 0
a.<a href="#isEmpty">isEmpty</a>(); // 真
</pre>
<p> <p>也可以參考<a href="#isEmpty">isEmpty</a>()和<a href="#length">length</a>()。
<p>實例:<a href="i18n-example.html#x1934">i18n/main.cpp</a>和<a href="qdir-example.html#x1835">qdir/qdir.cpp</a>。
<h3 class=fn>const char * <a name="latin1"></a>QString::latin1 () const
</h3>
返回字符串的Latin-1表述。注意如果字符串包含非Latin-1字符,返回值是不確定的。如果你想把字符串轉化為Unicode以為的格式,請參考<a href="qtextcodec.html">QTextCodec</a>類。
<p> 這個函數主要對于使用Unicode的開機時的老程序有用處。
<p> 只要源字符串的一個未修改復制存在,這個結果就保持有效。
<p> <p>也可以參考<a href="#utf8">utf8</a>()和<a href="#local8Bit">local8Bit</a>()。
<p>實例:<a href="fileiconview-example.html#x867">fileiconview/qfileiconview.cpp</a>和<a href="networkprotocol-example.html#x621">network/networkprotocol/nntp.cpp</a>。
<h3 class=fn><a href="qstring.html">QString</a> <a name="left"></a>QString::left ( uint len ) const
</h3>
返回包含字符串最左面的<em>len</em>個字符的子字符串。
<p> 如果<em>len</em>超過字符串的長度,則整個字符串被返回。
<p> <pre>
QString s = "Pineapple";
QString t = s.<a href="#left">left</a>( 4 ); // t == "Pine"
</pre>
<p> <p>也可以參考<a href="#right">right</a>()、<a href="#mid">mid</a>()和<a href="#isEmpty">isEmpty</a>()。
<p>實例:<a href="themes-example.html#x298">themes/themes.cpp</a>。
<h3 class=fn><a href="qstring.html">QString</a> <a name="leftJustify"></a>QString::leftJustify ( uint width, <a href="qchar.html">QChar</a> fill = ' ', bool truncate = FALSE ) const
</h3>
返回一個長度為<em>width</em>的,包含這個字符串,并且用<em>fill</em>填補的字符串。
<p> 如果<em>truncate</em>為假并且字符串的長度超過<em>width</em>,那么返回的字符串是這個字符串的復制。
<p> 如果<em>truncate</em>為真并且字符串的長度超過<em>width</em>,那么這個字符串的復制中超過<em>width</em>長度的任何字符都被移除并且這個復制被返回。
<p> <pre>
QString s( "apple" );
QString t = s.<a href="#leftJustify">leftJustify</a>( 8, '.' ); // t == "apple..."
</pre>
<p> <p>也可以參考<a href="#rightJustify">rightJustify</a>()。
<h3 class=fn>uint <a name="length"></a>QString::length () const
</h3>
<p> 返回字符串的長度。
<p> 零字符串和空字符串的長度都為0。
<p> <p>也可以參考<a href="#isNull">isNull</a>()和<a href="#isEmpty">isEmpty</a>()。
<p>實例:<a href="fileiconview-example.html#x868">fileiconview/qfileiconview.cpp</a>、<a href="networkprotocol-example.html#x622">network/networkprotocol/nntp.cpp</a>、<a href="rot-example.html#x1558">rot13/rot13.cpp</a>和<a href="themes-example.html#x299">themes/themes.cpp</a>。
<h3 class=fn><a href="qcstring.html">QCString</a> <a name="local8Bit"></a>QString::local8Bit () const
</h3>
Returns the string encoded in a locale-specific format. On X11, this
is the <a href="qtextcodec.html#codecForLocale">QTextCodec::codecForLocale</a>()。 On Windows, it is a system-defined
encoding. On Mac OS X, this always uses utf8 as the encoding.
<p> 關于Unicode字符串的編碼/解碼更多變化請參考<a href="qtextcodec.html">QTextCodec</a>。
<p> <p>也可以參考<a href="#fromLocal8Bit">QString::fromLocal8Bit</a>()、<a href="#latin1">latin1</a>()和<a href="#utf8">utf8</a>()。
<h3 class=fn>int <a name="localeAwareCompare"></a>QString::localeAwareCompare ( const <a href="qstring.html">QString</a> & s1, const <a href="qstring.html">QString</a> & s2 )<tt> [靜態]</tt>
</h3>
<p> 對<em>s1</em>和<em>s2</em>進行比較,如果<em>s1</em>小于、等于或者大于<em>s2</em>,就返回小于、等于或者大于0的整數。
<p> 這個比較是基于本地的并且也是基于平臺的方式。使用這個函數可以把排好序的字符串列表呈現給用戶。
<p> <p>也可以參考<a href="#compare">QString::compare</a>()和<a href="qtextcodec.html#locale">QTextCodec::locale</a>()。
<h3 class=fn>int <a name="localeAwareCompare-2"></a>QString::localeAwareCompare ( const <a href="qstring.html">QString</a> & s ) const
</h3>
這是一個重載成員函數,提供了方便。它的行為基本上和上面的函數相同。
<p> 對這個字符串和<em>s</em>進行比較。
<h3 class=fn><a href="qstring.html">QString</a> <a name="lower"></a>QString::lower () const
</h3>
返回由這個字符串轉換的小寫字符串。
<p> <pre>
QString string( "TROlltECH" );
str = string.<a href="#lower">lower</a>(); // str == "trolltech"
</pre>
<p> <p>也可以參考<a href="#upper">upper</a>()。
<p>實例:<a href="scribble-example.html#x962">scribble/scribble.cpp</a>。
<h3 class=fn><a href="qstring.html">QString</a> <a name="mid"></a>QString::mid ( uint index, uint len = 0xffffffff ) const
</h3>
返回包含這個字符串從<em>index</em>位置開始<em>len</em>個字符的字符串。
<p> 如果這個字符串為空或者<em>index</em>超出范圍,返回零。如果<em>index+len</em>超過這個字符串的長度,返回從<em>index</em>開始的整個字符串。
<p> <pre>
QString s( "Five pineapples" );
QString t = s.<a href="#mid">mid</a>( 5, 4 ); // t == "pine"
</pre>
<p> <p>也可以參考<a href="#left">left</a>()和<a href="#right">right</a>()。
<p>實例:<a href="mail-example.html#x763">network/mail/smtp.cpp</a>、<a href="qmag-example.html#x1646">qmag/qmag.cpp</a>和<a href="themes-example.html#x300">themes/themes.cpp</a>。
<h3 class=fn><a href="qstring.html">QString</a> <a name="number"></a>QString::number ( long n, int base = 10 )<tt> [靜態]</tt>
</h3>
一個把數字<em>n</em>轉換為字符串的方便函數,<em>n</em>被基于<em>base</em>表示,默認為10,并且必須在2到36之間。
<p> <pre>
long a = 63;
QString str = QString::<a href="#number">number</a>( a, 16 ); // str == "3f"
QString str = QString::<a href="#number">number</a>( a, 16 ).upper(); // str == "3F"
</pre>
<p> <p>也可以參考<a href="#setNum">setNum</a>()。
<p>實例:<a href="qaction-application-example.html#x1088">action/application.cpp</a>、<a href="simple-application-example.html#x1533">application/application.cpp</a>、<a href="canvas-chart-example.html#x2612">chart/chartform.cpp</a>、<a href="simple-qfont-demo-walkthrough.html#x2123">fonts/simple-qfont-demo/viewer.cpp</a>、<a href="mdi-example.html#x2039">mdi/application.cpp</a>和<a href="sql.html#x2192">sql/overview/extract/main.cpp</a>。
<h3 class=fn><a href="qstring.html">QString</a> <a name="number-2"></a>QString::number ( ulong n, int base = 10 )<tt> [靜態]</tt>
</h3>
這是一個重載成員函數,提供了方便。它的行為基本上和上面的函數相同。
<p> <p>也可以參考<a href="#setNum">setNum</a>()。
<h3 class=fn><a href="qstring.html">QString</a> <a name="number-3"></a>QString::number ( int n, int base = 10 )<tt> [靜態]</tt>
</h3>
這是一個重載成員函數,提供了方便。它的行為基本上和上面的函數相同。
<p> <p>也可以參考<a href="#setNum">setNum</a>()。
<h3 class=fn><a href="qstring.html">QString</a> <a name="number-4"></a>QString::number ( uint n, int base = 10 )<tt> [靜態]</tt>
</h3>
這是一個重載成員函數,提供了方便。它的行為基本上和上面的函數相同。
<p> 一個把數字<em>n</em>轉換為字符串表示的方便制造函數,<em>n</em>被基于<em>base</em>表示,默認為10,并且必須在2到36之間。
<p> <p>也可以參考<a href="#setNum">setNum</a>()。
<h3 class=fn><a href="qstring.html">QString</a> <a name="number-5"></a>QString::number ( double n, char f = 'g', int prec = 6 )<tt> [靜態]</tt>
</h3>
這是一個重載成員函數,提供了方便。它的行為基本上和上面的函數相同。
<p> 根據<em>fmt</em>指定的格式,參數<em>n</em>被格式化,<tt>g</tt>為默認情況并且可以為下列之一:
<p> <ul>
<li> <tt>e</tt> - 格式化為[-]9.9e[+|-]999
<li> <tt>E</tt> - 格式化為[-]9.9E[+|-]999
<li> <tt>f</tt> - 格式化為[-]9.9
<li> <tt>g</tt> - 使用<tt>e</tt>或<tt>f</tt>格式,看哪一個更簡練
<li> <tt>G</tt> - 使用<tt>E</tt>或<tt>f</tt>格式,看哪一個更簡練
</ul>
<p> 在所有的情況下,小數點之后數字的個數等于<em>prec</em>指定的精度。
<p> <pre>
double d = 12.34;
QString ds = <a href="#QString">QString</a>( "'E' format, precision 3, gives %1" )
.arg( d, 0, 'E', 3 );
// ds ==
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -