1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 13. StringUtils</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="Antelope Users Guide"><link rel="up" href="bk03.html" title="Additional Ant Tasks"><link rel="prev" href="bk03ch12.html" title="Chapter 12. FileUtils"><link rel="next" href="bk03ch14.html" title="Chapter 14. UID"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 13. StringUtils</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03ch12.html">Prev</a> </td><th width="60%" align="center">Additional Ant Tasks</th><td width="20%" align="right"> <a accesskey="n" href="bk03ch14.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="StringUtils"></a>Chapter 13. StringUtils</h2></div></div></div>
|
---|
2 | <STYLE TYPE="text/css"> <!-- @import url(./style.css); --> </STYLE>
|
---|
3 | <p>
|
---|
4 | The StringUtils task provides a number of useful string manipulation functions, such as converting a string to upper or lower case, trimming white space, finding a substring, etc. <span class="bold"><strong>Caution: this task does not follow the standard Ant convention of property immutability.</strong></span>
|
---|
5 | </p><p>
|
---|
6 | To use this task in your build files, include a task definition like this:
|
---|
7 | </p><p>
|
---|
8 | </p><pre class="programlisting">
|
---|
9 |
|
---|
10 | <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask"/>
|
---|
11 |
|
---|
12 | </pre><p>
|
---|
13 | </p><p>
|
---|
14 | </p><div class="table"><a name="id2522160"></a><p class="title"><b>Table 13.1. StringUtil Task Attributes</b></p><table summary="StringUtil Task Attributes" border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>string</td><td>The string to manipulate.</td><td>None</td><td>No</td></tr><tr><td>property</td><td>Where to store the manipulated string. Caution: this task will overwrite any existing property with this name.</td><td>None</td><td>No</td></tr></tbody></table></div><p>
|
---|
15 | </p><p>
|
---|
16 | Operations as nested elements:
|
---|
17 | </p><p>
|
---|
18 | </p><div class="table"><a name="id2522239"></a><p class="title"><b>Table 13.2. indexof, lastindexof: Find the index of or the last index of a substring.</b></p><table summary="indexof, lastindexof: Find the index of or the last index of a substring." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>string</td><td>The string to find the index of.</td><td>None</td><td>No</td></tr><tr><td>fromindex</td><td>Where to start looking.</td><td>0</td><td>No</td></tr></tbody></table></div><p>
|
---|
19 |
|
---|
20 |
|
---|
21 | </p><div class="table"><a name="id2522312"></a><p class="title"><b>Table 13.3. substring: Get a substring from the string.</b></p><table summary="substring: Get a substring from the string." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>beginindex</td><td>Start of substring.</td><td>0</td><td>No</td></tr><tr><td>endindex</td><td>End of substring.</td><td>End of string.</td><td>No</td></tr></tbody></table></div><p>
|
---|
22 |
|
---|
23 |
|
---|
24 | </p><div class="table"><a name="id2522383"></a><p class="title"><b>Table 13.4. replace: Replace parts of the string.</b></p><table summary="replace: Replace parts of the string." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>regex</td><td>Pattern to replace.</td><td>None</td><td>No</td></tr><tr><td>replacement</td><td>What to replace with.</td><td>None</td><td>No</td></tr></tbody></table></div><p>
|
---|
25 |
|
---|
26 | </p><div class="table"><a name="id2522455"></a><p class="title"><b>Table 13.5. sort: Sort items in a string.</b></p><table summary="sort: Sort items in a string." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>separator</td><td>The character separating individual items in the string.</td><td>Any of tab, new line, carriage return, line feed, or space.</td><td>No</td></tr></tbody></table></div><p>
|
---|
27 | This is useful for sorting a comma separated list or a property value that spans several lines.
|
---|
28 |
|
---|
29 | </p><p>
|
---|
30 | </p><div class="table"><a name="id2522516"></a><p class="title"><b>Table 13.6. messagebox: Put the string in a box for nice display.</b></p><table summary="messagebox: Put the string in a box for nice display." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>title</td><td>Title for the message box.</td><td>None</td><td>No</td></tr><tr><td>width</td><td>
|
---|
31 | Maximum width in characters for the message box. Lines
|
---|
32 | will be wrapped to fit inside the box. The box will not
|
---|
33 | stretch to this width if the message is less than
|
---|
34 | width - 4 characters wide.
|
---|
35 | </td><td>60</td><td>No</td></tr></tbody></table></div><p>
|
---|
36 | </p><p>
|
---|
37 | These operations have no attributes:
|
---|
38 | </p><div class="itemizedlist"><ul type="disc"><li><p>
|
---|
39 | <span class="bold"><strong>lowercase</strong></span> Converts the string to lowercase.
|
---|
40 | </p></li><li><p>
|
---|
41 | <span class="bold"><strong>uppercase</strong></span> Converts the string to uppercase.
|
---|
42 | </p></li><li><p>
|
---|
43 | <span class="bold"><strong>length</strong></span> Finds the length of the string.
|
---|
44 | </p></li><li><p>
|
---|
45 | <span class="bold"><strong>trim</strong></span> Removes white space from boths ends of the string.
|
---|
46 | </p></li></ul></div><p>
|
---|
47 |
|
---|
48 | </p><p>
|
---|
49 | More than one of the operations can be used at once, that is, you can convert a string to lowercase and trim it at the same time. See below for examples.
|
---|
50 | </p><p>
|
---|
51 | Examples:
|
---|
52 | </p><p>
|
---|
53 | Convert a string to lower case:
|
---|
54 | </p><pre class="programlisting">
|
---|
55 |
|
---|
56 | <target name="test1">
|
---|
57 | <property name="prop1" value="ABCDE"/>
|
---|
58 | <echo>prop1 before = ${prop1}</echo>
|
---|
59 | <a:stringutil string="${prop1}" property="prop1">
|
---|
60 | <a:lowercase/>
|
---|
61 | </a:stringutil>
|
---|
62 | <echo>prop1 after = ${prop1}</echo>
|
---|
63 | <a:assert message="prop1, expected abcde, got ${prop1}">
|
---|
64 | <bool>
|
---|
65 | <equals arg1="abcde" arg2="${prop1}"/>
|
---|
66 | </bool>
|
---|
67 | </a:assert>
|
---|
68 | </target>
|
---|
69 |
|
---|
70 | </pre><p>
|
---|
71 | </p><p>
|
---|
72 | Convert a string to upper case:
|
---|
73 | </p><pre class="programlisting">
|
---|
74 |
|
---|
75 | <target name="test2">
|
---|
76 | <property name="prop2" value="abcdefgh"/>
|
---|
77 | <echo>prop2 before = ${prop2}</echo>
|
---|
78 | <a:stringutil string="${prop2}" property="prop2">
|
---|
79 | <a:uppercase/>
|
---|
80 | </a:stringutil>
|
---|
81 | <echo>prop2 after = ${prop2}</echo>
|
---|
82 | <a:assert message="prop2, expected ABCDEFGH, got ${prop2}">
|
---|
83 | <bool>
|
---|
84 | <equals arg1="ABCDEFGH" arg2="${prop2}"/>
|
---|
85 | </bool>
|
---|
86 | </a:assert>
|
---|
87 | </target>
|
---|
88 |
|
---|
89 | </pre><p>
|
---|
90 | </p><p>
|
---|
91 | Convert a string to upper case and trim white space:
|
---|
92 | </p><pre class="programlisting">
|
---|
93 |
|
---|
94 | <target name="test3">
|
---|
95 | <property name="prop3" value=" abcdefgh "/>
|
---|
96 | <echo>prop3 before = ${prop3}</echo>
|
---|
97 | <a:stringutil string="${prop3}" property="prop3">
|
---|
98 | <a:uppercase/>
|
---|
99 | <a:trim/>
|
---|
100 | </a:stringutil>
|
---|
101 | <echo>prop3 after = ${prop3}</echo>
|
---|
102 | <a:assert message="prop3, expected ABCDEFGH, got ${prop3}">
|
---|
103 | <bool>
|
---|
104 | <equals arg1="ABCDEFGH" arg2="${prop3}"/>
|
---|
105 | </bool>
|
---|
106 | </a:assert>
|
---|
107 | </target>
|
---|
108 |
|
---|
109 | </pre><p>
|
---|
110 | </p><p>
|
---|
111 | Convert a string to upper case, trim white space, and find a substring:
|
---|
112 | </p><pre class="programlisting">
|
---|
113 |
|
---|
114 | <target name="test4">
|
---|
115 | <property name="prop4" value=" abcdefgh "/>
|
---|
116 | <echo>prop4 before = ${prop4}</echo>
|
---|
117 | <a:stringutil string="${prop4}" property="prop4">
|
---|
118 | <a:uppercase/>
|
---|
119 | <a:trim/>
|
---|
120 | <a:substring beginindex="3"/>
|
---|
121 | </a:stringutil>
|
---|
122 | <echo>prop4 after = ${prop4}</echo>
|
---|
123 | <a:assert message="prop4, expected DEFGH, got ${prop4}">
|
---|
124 | <bool>
|
---|
125 | <equals arg1="DEFGH" arg2="${prop4}"/>
|
---|
126 | </bool>
|
---|
127 | </a:assert>
|
---|
128 | </target>
|
---|
129 |
|
---|
130 | </pre><p>
|
---|
131 | </p><p>
|
---|
132 | Get the length of a string:
|
---|
133 | </p><pre class="programlisting">
|
---|
134 |
|
---|
135 | <target name="test7">
|
---|
136 | <property name="prop7" value="abcdefgh"/>
|
---|
137 | <echo>prop7 before = ${prop7}</echo>
|
---|
138 | <a:stringutil string="${prop7}" property="prop7">
|
---|
139 | <a:length/>
|
---|
140 | </a:stringutil>
|
---|
141 | <echo>prop7 length = ${prop7}</echo>
|
---|
142 | <a:assert message="prop7, expected 8, got ${prop7}">
|
---|
143 | <bool>
|
---|
144 | <mathequals arg1="8" arg2="${prop7}"/>
|
---|
145 | </bool>
|
---|
146 | </a:assert>
|
---|
147 | </target>
|
---|
148 |
|
---|
149 | </pre><p>
|
---|
150 | </p><p>
|
---|
151 | Sort a list:
|
---|
152 | </p><pre class="programlisting">
|
---|
153 |
|
---|
154 | <target name="test12">
|
---|
155 | <property name="prop12" value="a,b,c,d,e,f,g,h,a,b,c,d,e,f,g,h"/>
|
---|
156 | <echo>prop12 before = ${prop12}</echo>
|
---|
157 | <a:stringutil string="${prop12}" property="prop12">
|
---|
158 | <a:sort separator=","/>
|
---|
159 | </a:stringutil>
|
---|
160 | <echo>prop12 sorted = ${prop12}</echo>
|
---|
161 | <a:assert message="prop12, expected 'a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h', got ${prop12}">
|
---|
162 | <bool>
|
---|
163 | <equals arg1="a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h" arg2="${prop12}"/>
|
---|
164 | </bool>
|
---|
165 | </a:assert>
|
---|
166 | </target>
|
---|
167 |
|
---|
168 | </pre><p>
|
---|
169 | </p><p>
|
---|
170 | Message boxes:
|
---|
171 | </p><pre class="programlisting">
|
---|
172 |
|
---|
173 | <target name="test13">
|
---|
174 | <property name="prop13" value="Character boundary analysis allows users to interact with characters as they expect to, for example, when moving the cursor around through a text string. Character boundary analysis provides correct navigation of through character strings, regardless of how the character is stored. For example, an accented character might be stored as a base character and a diacritical mark. What users consider to be a character can differ between languages."/>
|
---|
175 | <echo>prop13 before = ${prop13}</echo>
|
---|
176 | <a:stringutil string="${prop13}" property="prop13">
|
---|
177 | <a:messagebox/>
|
---|
178 | </a:stringutil>
|
---|
179 | <echo>prop13 in messagebox:${line.separator}${prop13}</echo>
|
---|
180 |
|
---|
181 | <property name="prop13a" value="Character boundary analysis allows users to interact with characters as they expect to, for example, when moving the cursor around through a text string. Character boundary analysis provides correct navigation of through character strings, regardless of how the character is stored. For example, an accented character might be stored as a base character and a diacritical mark. What users consider to be a character can differ between languages."/>
|
---|
182 | <a:stringutil string="${prop13a}" property="prop13a">
|
---|
183 | <a:messagebox title="About Character Boundaries"/>
|
---|
184 | </a:stringutil>
|
---|
185 | <echo>prop13a in messagebox with title:${line.separator}${prop13a}</echo>
|
---|
186 |
|
---|
187 | </target>
|
---|
188 |
|
---|
189 | test13:
|
---|
190 | [echo] prop13 before = Character boundary analysis allows users to interact with characters as they expect to, for
|
---|
191 | example, when moving the cursor around through a text string. Character boundary analysis provides correct navigation of
|
---|
192 | through character strings, regardless of how the character is stored. For example, an accented character might be store
|
---|
193 | d as a base character and a diacritical mark. What users consider to be a character can differ between languages.
|
---|
194 | [echo] prop13 in messagebox:
|
---|
195 | [echo]
|
---|
196 | [echo] +----------------------------------------------------------------------+
|
---|
197 | [echo] | Character boundary analysis allows users to interact with characters |
|
---|
198 | [echo] | as they expect to, for example, when moving the cursor around |
|
---|
199 | [echo] | through a text string. Character boundary analysis provides correct |
|
---|
200 | [echo] | navigation of through character strings, regardless of how the |
|
---|
201 | [echo] | character is stored. For example, an accented character might |
|
---|
202 | [echo] | be stored as a base character and a diacritical mark. What users |
|
---|
203 | [echo] | consider to be a character can differ between languages. |
|
---|
204 | [echo] +----------------------------------------------------------------------+
|
---|
205 | [echo] prop13a in messagebox with title:
|
---|
206 | [echo]
|
---|
207 | [echo] +----------------------------------------------------------------------+
|
---|
208 | [echo] | About Character Boundaries |
|
---|
209 | [echo] +----------------------------------------------------------------------+
|
---|
210 | [echo] | Character boundary analysis allows users to interact with characters |
|
---|
211 | [echo] | as they expect to, for example, when moving the cursor around |
|
---|
212 | [echo] | through a text string. Character boundary analysis provides correct |
|
---|
213 | [echo] | navigation of through character strings, regardless of how the |
|
---|
214 | [echo] | character is stored. For example, an accented character might |
|
---|
215 | [echo] | be stored as a base character and a diacritical mark. What users |
|
---|
216 | [echo] | consider to be a character can differ between languages. |
|
---|
217 | [echo] +----------------------------------------------------------------------+
|
---|
218 | [antlib:ise.antelope.tasks:testcase] test13 passed.
|
---|
219 |
|
---|
220 | </pre><p>
|
---|
221 | </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03ch12.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk03ch14.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 12. FileUtils </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 14. UID</td></tr></table></div></body></html>
|
---|