1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/qstringlist.cpp:46 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QStringList Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <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>
|
---|
33 |
|
---|
34 | <p>The QStringList class provides a list of strings.
|
---|
35 | <a href="#details">More...</a>
|
---|
36 | <p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
|
---|
37 | <p><tt>#include <<a href="qstringlist-h.html">qstringlist.h</a>></tt>
|
---|
38 | <p>Inherits <a href="qvaluelist.html">QValueList</a><QString>.
|
---|
39 | <p><a href="qstringlist-members.html">List of all member functions.</a>
|
---|
40 | <h2>Public Members</h2>
|
---|
41 | <ul>
|
---|
42 | <li class=fn><a href="#QStringList"><b>QStringList</b></a> ()</li>
|
---|
43 | <li class=fn><a href="#QStringList-2"><b>QStringList</b></a> ( const QStringList & l )</li>
|
---|
44 | <li class=fn><a href="#QStringList-3"><b>QStringList</b></a> ( const QValueList<QString> & l )</li>
|
---|
45 | <li class=fn><a href="#QStringList-4"><b>QStringList</b></a> ( const QString & i )</li>
|
---|
46 | <li class=fn><a href="#QStringList-5"><b>QStringList</b></a> ( const char * i )</li>
|
---|
47 | <li class=fn>void <a href="#sort"><b>sort</b></a> ()</li>
|
---|
48 | <li class=fn>QString <a href="#join"><b>join</b></a> ( const QString & sep ) const</li>
|
---|
49 | <li class=fn>QStringList <a href="#grep"><b>grep</b></a> ( const QString & str, bool cs = TRUE ) const</li>
|
---|
50 | <li class=fn>QStringList <a href="#grep-2"><b>grep</b></a> ( const QRegExp & rx ) const</li>
|
---|
51 | <li class=fn>QStringList & <a href="#gres"><b>gres</b></a> ( const QString & before, const QString & after, bool cs = TRUE )</li>
|
---|
52 | <li class=fn>QStringList & <a href="#gres-2"><b>gres</b></a> ( const QRegExp & rx, const QString & after )</li>
|
---|
53 | </ul>
|
---|
54 | <h2>Static Public Members</h2>
|
---|
55 | <ul>
|
---|
56 | <li class=fn>QStringList <a href="#fromStrList"><b>fromStrList</b></a> ( const QStrList & ascii )</li>
|
---|
57 | <li class=fn>QStringList <a href="#split-2"><b>split</b></a> ( const QString & sep, const QString & str, bool allowEmptyEntries = FALSE )</li>
|
---|
58 | <li class=fn>QStringList <a href="#split-3"><b>split</b></a> ( const QChar & sep, const QString & str, bool allowEmptyEntries = FALSE )</li>
|
---|
59 | <li class=fn>QStringList <a href="#split"><b>split</b></a> ( const QRegExp & sep, const QString & str, bool allowEmptyEntries = FALSE )</li>
|
---|
60 | </ul>
|
---|
61 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | The QStringList class provides a list of strings.
|
---|
66 | <p>
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | <p> It is used to store and manipulate strings that logically belong
|
---|
71 | together. Essentially QStringList is a <a href="qvaluelist.html">QValueList</a> of <a href="qstring.html">QString</a>
|
---|
72 | objects. Unlike <a href="qstrlist.html">QStrList</a>, which stores pointers to characters,
|
---|
73 | QStringList holds real QString objects. It is the class of choice
|
---|
74 | whenever you work with Unicode strings. QStringList is part of the
|
---|
75 | <a href="qtl.html">Qt Template Library</a>.
|
---|
76 | <p> Like QString itself, QStringList objects are <a href="shclass.html#implicitly-shared">implicitly shared</a>, so
|
---|
77 | passing them around as value-parameters is both fast and safe.
|
---|
78 | <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
|
---|
79 | <a href="qvaluelist.html#operator-lt-lt">operator<<</a>(), e.g.
|
---|
80 | <pre>
|
---|
81 | QStringList fonts;
|
---|
82 | fonts.<a href="qvaluelist.html#append">append</a>( "Times" );
|
---|
83 | fonts += "Courier";
|
---|
84 | fonts += "Courier New";
|
---|
85 | fonts << "Helvetica [Cronyx]" << "Helvetica [Adobe]";
|
---|
86 | </pre>
|
---|
87 |
|
---|
88 | <p> String lists have an iterator, QStringList::Iterator(), e.g.
|
---|
89 | <pre>
|
---|
90 | for ( QStringList::<a href="qvaluelist.html#Iterator">Iterator</a> it = fonts.begin(); it != fonts.end(); ++it ) {
|
---|
91 | cout << *it << ":";
|
---|
92 | }
|
---|
93 | cout << endl;
|
---|
94 | // Output:
|
---|
95 | // Times:Courier:Courier New:Helvetica [Cronyx]:Helvetica [Adobe]:
|
---|
96 | </pre>
|
---|
97 |
|
---|
98 | <p> Many Qt functions return string lists by value; to iterate over
|
---|
99 | these you should make a copy and iterate over the copy.
|
---|
100 | <p> You can concatenate all the strings in a string list into a single
|
---|
101 | string (with an optional separator) using <a href="#join">join</a>(), e.g.
|
---|
102 | <pre>
|
---|
103 | <a href="qstring.html">QString</a> allFonts = fonts.join( ", " );
|
---|
104 | cout << allFonts << endl;
|
---|
105 | // Output:
|
---|
106 | // Times, Courier, Courier New, Helvetica [Cronyx], Helvetica [Adobe]
|
---|
107 | </pre>
|
---|
108 |
|
---|
109 | <p> You can sort the list with <a href="#sort">sort</a>(), and extract a new list which
|
---|
110 | contains only those strings which contain a particular substring
|
---|
111 | (or match a particular <a href="qregexp.html#regular-expression">regular expression</a>) using the <a href="#grep">grep</a>()
|
---|
112 | functions, e.g.
|
---|
113 | <pre>
|
---|
114 | fonts.sort();
|
---|
115 | cout << fonts.join( ", " ) << endl;
|
---|
116 | // Output:
|
---|
117 | // Courier, Courier New, Helvetica [Adobe], Helvetica [Cronyx], Times
|
---|
118 |
|
---|
119 | QStringList helveticas = fonts.grep( "Helvetica" );
|
---|
120 | cout << helveticas.<a href="#join">join</a>( ", " ) << endl;
|
---|
121 | // Output:
|
---|
122 | // Helvetica [Adobe], Helvetica [Cronyx]
|
---|
123 | </pre>
|
---|
124 |
|
---|
125 | <p> Existing strings can be split into string lists with character,
|
---|
126 | string or regular expression separators, e.g.
|
---|
127 | <pre>
|
---|
128 | <a href="qstring.html">QString</a> s = "Red\tGreen\tBlue";
|
---|
129 | QStringList colors = QStringList::<a href="#split">split</a>( "\t", s );
|
---|
130 | cout << colors.<a href="#join">join</a>( ", " ) << endl;
|
---|
131 | // Output:
|
---|
132 | // Red, Green, Blue
|
---|
133 | </pre>
|
---|
134 |
|
---|
135 | <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>.
|
---|
136 |
|
---|
137 | <hr><h2>Member Function Documentation</h2>
|
---|
138 | <h3 class=fn><a name="QStringList"></a>QStringList::QStringList ()
|
---|
139 | </h3>
|
---|
140 |
|
---|
141 | <p> Creates an empty string list.
|
---|
142 |
|
---|
143 | <h3 class=fn><a name="QStringList-2"></a>QStringList::QStringList ( const <a href="qstringlist.html">QStringList</a> & l )
|
---|
144 | </h3>
|
---|
145 |
|
---|
146 | <p> Creates a copy of the list <em>l</em>. This function is very fast
|
---|
147 | because QStringList is <a href="shclass.html#implicitly-shared">implicitly shared</a>. In most situations this
|
---|
148 | acts like a <a href="shclass.html#deep-copy">deep copy</a>, for example, if this list or the original
|
---|
149 | one or some other list referencing the same shared data is
|
---|
150 | modified, the modifying list first makes a copy, i.e.
|
---|
151 | copy-on-write.
|
---|
152 | In a threaded environment you may require a real deep copy
|
---|
153 | .
|
---|
154 |
|
---|
155 | <h3 class=fn><a name="QStringList-3"></a>QStringList::QStringList ( const <a href="qvaluelist.html">QValueList</a><QString> & l )
|
---|
156 | </h3>
|
---|
157 |
|
---|
158 | <p> Constructs a new string list that is a copy of <em>l</em>.
|
---|
159 |
|
---|
160 | <h3 class=fn><a name="QStringList-4"></a>QStringList::QStringList ( const <a href="qstring.html">QString</a> & i )
|
---|
161 | </h3>
|
---|
162 |
|
---|
163 | <p> Constructs a string list consisting of the single string <em>i</em>.
|
---|
164 | Longer lists are easily created as follows:
|
---|
165 | <p> <pre>
|
---|
166 | QStringList items;
|
---|
167 | items << "Buy" << "Sell" << "Update" << "Value";
|
---|
168 | </pre>
|
---|
169 |
|
---|
170 |
|
---|
171 | <h3 class=fn><a name="QStringList-5"></a>QStringList::QStringList ( const char * i )
|
---|
172 | </h3>
|
---|
173 |
|
---|
174 | <p> Constructs a string list consisting of the single Latin-1 string <em>i</em>.
|
---|
175 |
|
---|
176 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="fromStrList"></a>QStringList::fromStrList ( const <a href="qstrlist.html">QStrList</a> & ascii )<tt> [static]</tt>
|
---|
177 | </h3>
|
---|
178 | Converts from an ASCII-QStrList <em>ascii</em> to a QStringList (Unicode).
|
---|
179 |
|
---|
180 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="grep"></a>QStringList::grep ( const <a href="qstring.html">QString</a> & str, bool cs = TRUE ) const
|
---|
181 | </h3>
|
---|
182 | Returns a list of all the strings containing the substring <em>str</em>.
|
---|
183 | <p> If <em>cs</em> is TRUE, the grep is done case-sensitively; otherwise
|
---|
184 | case is ignored.
|
---|
185 | <p> <pre>
|
---|
186 | QStringList list;
|
---|
187 | list << "Bill Gates" << "John Doe" << "Bill Clinton";
|
---|
188 | list = list.<a href="#grep">grep</a>( "Bill" );
|
---|
189 | // list == ["Bill Gates", "Bill Clinton"]
|
---|
190 | </pre>
|
---|
191 |
|
---|
192 | <p> <p>See also <a href="qstring.html#find">QString::find</a>().
|
---|
193 |
|
---|
194 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="grep-2"></a>QStringList::grep ( const <a href="qregexp.html">QRegExp</a> & rx ) const
|
---|
195 | </h3>
|
---|
196 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
197 | <p> Returns a list of all the strings that match the <a href="qregexp.html#regular-expression">regular expression</a> <em>rx</em>.
|
---|
198 | <p> <p>See also <a href="qstring.html#find">QString::find</a>().
|
---|
199 |
|
---|
200 | <h3 class=fn><a href="qstringlist.html">QStringList</a> & <a name="gres"></a>QStringList::gres ( const <a href="qstring.html">QString</a> & before, const <a href="qstring.html">QString</a> & after, bool cs = TRUE )
|
---|
201 | </h3>
|
---|
202 | Replaces every occurrence of the string <em>before</em> in the strings
|
---|
203 | that constitute the string list with the string <em>after</em>. Returns
|
---|
204 | a reference to the string list.
|
---|
205 | <p> If <em>cs</em> is TRUE, the search is case sensitive; otherwise the
|
---|
206 | search is case insensitive.
|
---|
207 | <p> Example:
|
---|
208 | <pre>
|
---|
209 | QStringList list;
|
---|
210 | list << "alpha" << "beta" << "gamma" << "epsilon";
|
---|
211 | list.<a href="#gres">gres</a>( "a", "o" );
|
---|
212 | // list == ["olpho", "beto", "gommo", "epsilon"]
|
---|
213 | </pre>
|
---|
214 |
|
---|
215 | <p> <p>See also <a href="qstring.html#replace">QString::replace</a>().
|
---|
216 |
|
---|
217 | <h3 class=fn><a href="qstringlist.html">QStringList</a> & <a name="gres-2"></a>QStringList::gres ( const <a href="qregexp.html">QRegExp</a> & rx, const <a href="qstring.html">QString</a> & after )
|
---|
218 | </h3>
|
---|
219 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
220 | <p> Replaces every occurrence of the regexp <em>rx</em> in the string
|
---|
221 | with <em>after</em>. Returns a reference to the string list.
|
---|
222 | <p> Example:
|
---|
223 | <pre>
|
---|
224 | QStringList list;
|
---|
225 | list << "alpha" << "beta" << "gamma" << "epsilon";
|
---|
226 | list.<a href="#gres">gres</a>( QRegExp("^a"), "o" );
|
---|
227 | // list == ["olpha", "beta", "gamma", "epsilon"]
|
---|
228 | </pre>
|
---|
229 |
|
---|
230 | <p> For regexps containing <a href="qregexp.html#capturing-text">capturing parentheses</a>, occurrences of <b>\1</b>,
|
---|
231 | <b>\2</b>, ..., in <em>after</em> are replaced with <em>rx</em>.cap(1),
|
---|
232 | cap(2), ...
|
---|
233 | <p> Example:
|
---|
234 | <pre>
|
---|
235 | QStringList list;
|
---|
236 | list << "Bill Clinton" << "Gates, Bill";
|
---|
237 | list.<a href="#gres">gres</a>( QRegExp("^(.*), (.*)$"), "\\2 \\1" );
|
---|
238 | // list == ["Bill Clinton", "Bill Gates"]
|
---|
239 | </pre>
|
---|
240 |
|
---|
241 | <p> <p>See also <a href="qstring.html#replace">QString::replace</a>().
|
---|
242 |
|
---|
243 | <h3 class=fn><a href="qstring.html">QString</a> <a name="join"></a>QStringList::join ( const <a href="qstring.html">QString</a> & sep ) const
|
---|
244 | </h3>
|
---|
245 | Joins the string list into a single string with each element
|
---|
246 | separated by the string <em>sep</em> (which can be empty).
|
---|
247 | <p> <p>See also <a href="#split">split</a>().
|
---|
248 |
|
---|
249 | <p>Examples: <a href="fileiconview-example.html#x872">fileiconview/qfileiconview.cpp</a> and <a href="toplevel-example.html#x2533">toplevel/options.ui.h</a>.
|
---|
250 | <h3 class=fn>void <a name="sort"></a>QStringList::sort ()
|
---|
251 | </h3>
|
---|
252 | Sorts the list of strings in ascending case-sensitive order.
|
---|
253 | <p> Sorting is very fast. It uses the <a href="qtl.html">Qt Template
|
---|
254 | Library's</a> efficient HeapSort implementation that has a
|
---|
255 | time complexity of O(n*log n).
|
---|
256 | <p> If you want to sort your strings in an arbitrary order consider
|
---|
257 | using a <a href="qmap.html">QMap</a>. For example you could use a QMap<QString,QString>
|
---|
258 | to create a case-insensitive ordering (e.g. mapping the lowercase
|
---|
259 | text to the text), or a QMap<int,QString> to sort the strings by
|
---|
260 | some integer index, etc.
|
---|
261 |
|
---|
262 | <p>Example: <a href="themes-example.html#x341">themes/themes.cpp</a>.
|
---|
263 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="split"></a>QStringList::split ( const <a href="qregexp.html">QRegExp</a> & sep, const <a href="qstring.html">QString</a> & str, bool allowEmptyEntries = FALSE )<tt> [static]</tt>
|
---|
264 | </h3>
|
---|
265 | 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.
|
---|
266 | <p> If <em>allowEmptyEntries</em> is TRUE, a null string is inserted in
|
---|
267 | the list wherever the separator matches twice without intervening
|
---|
268 | text.
|
---|
269 | <p> For example, if you split the string "a,,b,c" on commas, <a href="#split">split</a>()
|
---|
270 | returns the three-item list "a", "b", "c" if <em>allowEmptyEntries</em>
|
---|
271 | is FALSE (the default), and the four-item list "a", "", "b", "c"
|
---|
272 | if <em>allowEmptyEntries</em> is TRUE.
|
---|
273 | <p> If <em>sep</em> does not match anywhere in <em>str</em>, split() returns a
|
---|
274 | single element list with the element containing the single string
|
---|
275 | <em>str</em>.
|
---|
276 | <p> <p>See also <a href="#join">join</a>() and <a href="qstring.html#section">QString::section</a>().
|
---|
277 |
|
---|
278 | <p>Examples: <a href="tutorial2-03.html#x2552">chart/element.cpp</a>, <a href="dirview-example.html#x1703">dirview/dirview.cpp</a>, and <a href="httpd-example.html#x733">network/httpd/httpd.cpp</a>.
|
---|
279 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="split-2"></a>QStringList::split ( const <a href="qstring.html">QString</a> & sep, const <a href="qstring.html">QString</a> & str, bool allowEmptyEntries = FALSE )<tt> [static]</tt>
|
---|
280 | </h3>
|
---|
281 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
282 | <p> This version of the function uses a <a href="qstring.html">QString</a> as separator, rather
|
---|
283 | than a <a href="qregexp.html#regular-expression">regular expression</a>.
|
---|
284 | <p> If <em>sep</em> is an empty string, the return value is a list of
|
---|
285 | one-character strings: <a href="#split">split</a>( QString( "" ), "four" ) returns the
|
---|
286 | four-item list, "f", "o", "u", "r".
|
---|
287 | <p> If <em>allowEmptyEntries</em> is TRUE, a null string is inserted in
|
---|
288 | the list wherever the separator matches twice without intervening
|
---|
289 | text.
|
---|
290 | <p> <p>See also <a href="#join">join</a>() and <a href="qstring.html#section">QString::section</a>().
|
---|
291 |
|
---|
292 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="split-3"></a>QStringList::split ( const <a href="qchar.html">QChar</a> & sep, const <a href="qstring.html">QString</a> & str, bool allowEmptyEntries = FALSE )<tt> [static]</tt>
|
---|
293 | </h3>
|
---|
294 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
295 | <p> This version of the function uses a <a href="qchar.html">QChar</a> as separator, rather
|
---|
296 | than a <a href="qregexp.html#regular-expression">regular expression</a>.
|
---|
297 | <p> <p>See also <a href="#join">join</a>() and <a href="qstring.html#section">QString::section</a>().
|
---|
298 |
|
---|
299 | <!-- eof -->
|
---|
300 | <hr><p>
|
---|
301 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
302 | Copyright © 1995-2007
|
---|
303 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
304 | <table width=100% cellspacing=0 border=0><tr>
|
---|
305 | <td>Copyright © 2007
|
---|
306 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
307 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
308 | </table></div></address></body>
|
---|
309 | </html>
|
---|