Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 1862

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/tools/qstringlist.cpp:46 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QStringList Class</title>
<style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QStringList Class Reference</h1>

<p>The QStringList class provides a list of strings.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qstringlist-h.html">qstringlist.h</a>&gt;</tt>
<p>Inherits <a href="qvaluelist.html">QValueList</a>&lt;QString&gt;.
<p><a href="qstringlist-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class=fn><a href="#QStringList"><b>QStringList</b></a> ()</div></li>
<li><div class=fn><a href="#QStringList-2"><b>QStringList</b></a> ( const&nbsp;QStringList&nbsp;&amp;&nbsp;l )</div></li>
<li><div class=fn><a href="#QStringList-3"><b>QStringList</b></a> ( const&nbsp;QValueList&lt;QString&gt;&nbsp;&amp;&nbsp;l )</div></li>
<li><div class=fn><a href="#QStringList-4"><b>QStringList</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;i )</div></li>
<li><div class=fn><a href="#QStringList-5"><b>QStringList</b></a> ( const&nbsp;char&nbsp;*&nbsp;i )</div></li>
<li><div class=fn>void <a href="#sort"><b>sort</b></a> ()</div></li>
<li><div class=fn>QString <a href="#join"><b>join</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;sep ) const</div></li>
<li><div class=fn>QStringList <a href="#grep"><b>grep</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;str, bool&nbsp;cs = TRUE ) const</div></li>
<li><div class=fn>QStringList <a href="#grep-2"><b>grep</b></a> ( const&nbsp;QRegExp&nbsp;&amp;&nbsp;expr ) const</div></li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li><div class=fn>QStringList <a href="#fromStrList"><b>fromStrList</b></a> ( const&nbsp;QStrList&nbsp;&amp;&nbsp;ascii )</div></li>
<li><div class=fn>QStringList <a href="#split-2"><b>split</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;sep, const&nbsp;QString&nbsp;&amp;&nbsp;str, bool&nbsp;allowEmptyEntries = FALSE )</div></li>
<li><div class=fn>QStringList <a href="#split-3"><b>split</b></a> ( const&nbsp;QChar&nbsp;&amp;&nbsp;sep, const&nbsp;QString&nbsp;&amp;&nbsp;str, bool&nbsp;allowEmptyEntries = FALSE )</div></li>
<li><div class=fn>QStringList <a href="#split"><b>split</b></a> ( const&nbsp;QRegExp&nbsp;&amp;&nbsp;sep, const&nbsp;QString&nbsp;&amp;&nbsp;str, bool&nbsp;allowEmptyEntries = FALSE )</div></li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>


The QStringList class provides a list of strings.
<p> 



<p> It is used to store and manipulate strings that logically belong
together.  Basically QStringList is a <a href="qvaluelist.html">QValueList</a> of <a href="qstring.html">QString</a>
objects. As opposed to <a href="qstrlist.html">QStrList</a>, which stores pointers to
characters, QStringList deals with real QString objects.  It is the
class of choice whenever you work with Unicode strings. QStringList
is part of the <a href="qtl.html"> Qt Template Library</a>.
<p> Like QString itself, QStringList objects are <a href="shclass.html#implicitly-shared">implicitly shared</a>.
Passing them around as value-parameters is both fast and safe.
<p> Strings can be added to a list using <a href="qvaluelist.html#append">append</a>(), <a href="qvaluelist.html#operator+-eq">operator+=</a>() or
<a href="qvaluelist.html#operator-lt-lt">operator&lt;&lt;</a>(), e.g.
<pre>
    QStringList fonts;
    fonts.<a href="qvaluelist.html#append">append</a>( "Times" );
    fonts += "Courier";
    fonts += "Courier New";
    fonts &lt;&lt; "Helvetica [Cronyx]" &lt;&lt; "Helvetica [Adobe]";
    </pre>
 
<p> String lists have an iterator, QStringList::Iterator(), e.g.
<pre>
    for ( QStringList::<a href="qvaluelist.html#Iterator">Iterator</a> it = fonts.begin(); it != fonts.end(); ++it ) {
        cout &lt;&lt; *it &lt;&lt; ":";
    }
    cout &lt;&lt; endl;
    // Output:
    //  Times:Courier:Courier New:Helvetica [Cronyx]:Helvetica [Adobe]:
    </pre>
 
<p> Many Qt functions return const string lists; to iterate over these
you should make a copy and iterate over the copy.
<p> You can concatenate all the strings in a string list into a single
string (with an optional separator) using <a href="#join">join</a>(), e.g.
<pre>
    <a href="qstring.html">QString</a> allFonts = fonts.join( ", " );
    cout &lt;&lt; allFonts &lt;&lt; endl;
    // Output:
    //  Times, Courier, Courier New, Helvetica [Cronyx], Helvetica [Adobe]
    </pre>
 
<p> You can sort the list with <a href="#sort">sort</a>(), and extract a new list which
contains only those strings which contain a particular substring
(or match a particular <a href="qregexp.html#regular-expression">regular expression</a>) using the
<a href="#grep">grep</a>() functions, e.g.
<pre>
    fonts.sort();
    cout &lt;&lt; fonts.join( ", " ) &lt;&lt; endl;
    // Output:
    //  Courier, Courier New, Helvetica [Adobe], Helvetica [Cronyx], Times

    QStringList helveticas = fonts.grep( "Helvetica" );
    cout &lt;&lt; helveticas.<a href="#join">join</a>( ", " ) &lt;&lt; endl;
    // Output:
    //  Helvetica [Adobe], Helvetica [Cronyx]
    </pre>
 
<p> Existing strings can be split into string lists with character,
string or regular expression separators, e.g.
<pre>
    <a href="qstring.html">QString</a> s = "Red\tGreen\tBlue";
    QStringList colors = QStringList::<a href="#split">split</a>( "\t", s );
    cout &lt;&lt; colors.<a href="#join">join</a>( ", " ) &lt;&lt; endl;
    // Output:
    //  Red, Green, Blue
    </pre>
 
<p> <p>See also <a href="shared.html">Implicitly and Explicitly Shared Classes</a>, <a href="text.html">Text Related Classes</a> and <a href="tools.html">Non-GUI Classes</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QStringList"></a>QStringList::QStringList ()
</h3>

Creates an empty string list.

<h3 class=fn><a name="QStringList-2"></a>QStringList::QStringList ( const&nbsp;<a href="qstringlist.html">QStringList</a>&nbsp;&amp;&nbsp;l )
</h3> 
<p> Creates a copy of the list <em>l</em>. This function is very fast because
QStringList is <a href="shclass.html#implicitly-shared">implicitly shared</a>. However, for the programmer this
is the same as a <a href="shclass.html#deep-copy">deep copy</a>. If this list or the original one or some
other list referencing the same shared data is modified, the
modifying list first makes a copy, i.e. copy-on-write.

<h3 class=fn><a name="QStringList-3"></a>QStringList::QStringList ( const&nbsp;<a href="qvaluelist.html">QValueList</a>&lt;QString&gt;&nbsp;&amp;&nbsp;l )
</h3> 
<p> Constructs a new string list that is a copy of <em>l</em>.

<h3 class=fn><a name="QStringList-4"></a>QStringList::QStringList ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;i )
</h3>

<p> Constructs a string list consisting of the single string <em>i</em>.
Longer lists are easily created as follows:
<p> <pre>
    QStringList items;
    items &lt;&lt; "Buy" &lt;&lt; "Sell" &lt;&lt; "Update" &lt;&lt; "Value";
    </pre>
 

<h3 class=fn><a name="QStringList-5"></a>QStringList::QStringList ( const&nbsp;char&nbsp;*&nbsp;i )
</h3>

Constructs a string list consisting of the single latin-1 string <em>i</em>.

<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="fromStrList"></a>QStringList::fromStrList ( const&nbsp;<a href="qstrlist.html">QStrList</a>&nbsp;&amp;&nbsp;ascii )<tt> [static]</tt>
</h3> Converts from an ASCII-QStrList <em>ascii</em> to a QStringList (Unicode).

<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="grep"></a>QStringList::grep ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;str, bool&nbsp;cs = TRUE ) const
</h3>
Returns a list of all strings containing the substring <em>str</em>.
<p> If <em>cs</em> is TRUE, the grep is done case-sensitively; otherwise case
is ignored.

<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="grep-2"></a>QStringList::grep ( const&nbsp;<a href="qregexp.html">QRegExp</a>&nbsp;&amp;&nbsp;expr ) const
</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns a list of all the strings that contain a substring that matches
the <a href="qregexp.html#regular-expression">regular expression</a> <em>expr</em>.

<h3 class=fn><a href="qstring.html">QString</a> <a name="join"></a>QStringList::join ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;sep ) const
</h3>
Joins the string list into a single string with each element
separated by the string <em>sep</em>.
<p> <p>See also <a href="#split">split</a>().

<h3 class=fn>void <a name="sort"></a>QStringList::sort ()
</h3>
Sorts the list of strings in ascending case-sensitive order.
<p> Sorting is very fast. It uses the Qt Template Library's efficient
HeapSort implementation that has a time complexity of O(n*log n).
<p> If you want to sort your strings in an arbitrary order consider
using a <a href="qmap.html">QMap</a>. For example you could use a QMap&lt;QString,QString&gt; to
create a case-insensitive ordering (e.g. mapping the lowercase text
to the text), or a QMap&lt;int,QString&gt; to sort the strings by some
integer index, etc.

<p>Example: <a href="themes-example.html#x358">themes/themes.cpp</a>.
<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="split"></a>QStringList::split ( const&nbsp;<a href="qregexp.html">QRegExp</a>&nbsp;&amp;&nbsp;sep, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;str, bool&nbsp;allowEmptyEntries = FALSE )<tt> [static]</tt>
</h3> Splits the string <em>str</em> into strings wherever the
<a href="qregexp.html#regular-expression">regular expression</a> <em>sep</em> occurs, and
returns the list of those strings.
<p> If <em>allowEmptyEntries</em> is TRUE, an empty string is inserted in the
list wherever the separator matches twice without intervening
text.
<p> For example, if you split the string "a,,b,c" on commas, <a href="#split">split</a>()
returns the three-item list "a", "b", "c" if <em>allowEmptyEntries</em> is
FALSE (the default), and the four-item list "a", "", "b", "c" if <em>allowEmptyEntries</em> is TRUE.
<p> If <em>sep</em> does not match anywhere in <em>str</em>, split() returns a list
consisting of the single string <em>str</em>.
<p> <p>See also <a href="#join">join</a>() and <a href="qstring.html#section">QString::section</a>().

<p>Examples: <a href="dirview-example.html#x1697">dirview/dirview.cpp</a> and <a href="httpd-example.html#x998">network/httpd/httpd.cpp</a>.
<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="split-2"></a>QStringList::split ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;sep, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;str, bool&nbsp;allowEmptyEntries = FALSE )<tt> [static]</tt>
</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> This version of the function uses a <a href="qstring.html">QString</a> as separator, rather than
a <a href="qregexp.html#regular-expression">regular expression</a>.
<p> If <em>sep</em> is an empty string, the return value is a list of
one-character strings: <a href="#split">split</a>( QString( "" ), "mfc" ) returns the
three-item list, "m", "f", "c".
<p> If <em>allowEmptyEntries</em> is TRUE, an empty string is inserted in the
list wherever the separator matches twice without intervening
text.
<p> <p>See also <a href="#join">join</a>() and <a href="qstring.html#section">QString::section</a>().

<h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="split-3"></a>QStringList::split ( const&nbsp;<a href="qchar.html">QChar</a>&nbsp;&amp;&nbsp;sep, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;str, bool&nbsp;allowEmptyEntries = FALSE )<tt> [static]</tt>
</h3> This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> This version of the function uses a <a href="qchar.html">QChar</a> as separator, rather than
a <a href="qregexp.html#regular-expression">regular expression</a>.
<p> <p>See also <a href="#join">join</a>() and <a href="qstring.html#section">QString::section</a>().

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2001
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>