📄 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 + -