Font size:
String-List
Description
The string-list ant task takes a delimited string, and provides various list actions.
General syntax:
<string-list list="e1,e2,e3" delimiter="," resultproperty="result">
<action>input</action >
</string-list>
Parameters
| Attribute | Description | Required |
|---|---|---|
| list | Value containing list | Yes |
| resultproperty | Property name to store result. | No. defaults to "result" |
| delimiter | String delimiting elements in the list value | No. defaults to "," (comma) |
Parameters specified as nested elements
The string-list task takes one action element.
| action | description | input data |
|---|---|---|
| contains | Checks if list contains value. If the value is found resultproperty is set true, otherwise the property is not set. | value to find |
| get | Retrieves element from list. Takes an index number or optionally a regex pattern if regex=true. | an integer or a regex pattern if regex attribute is set true |
| add | Adds element to list | value to add |
| remove | Removes element from list | value to remove |
| reverse | Reverses elements in list. | none |
| size | Counts elements in list | none |
Examples
The examples below show off a variety of string-list actions.
<!-- count the elements -->
<string-list list="one,two,three"
delimiter=","
resultproperty="list.size">
<size/>
</string-list>
<!-- check if the list contains the value, one -->
<string-list list="one,two,three" resultproperty="contains.one">
<contains>one</contains>
</string-list>
<!-- get the first element -->
<string-list list="one,two,three" resultproperty="list.zeroth">
<get>0</get>
</string-list>
<!-- retreive the element by a regex pattern -->
<string-list list="one,two,three" resultproperty="list.get.regex">
<get regex="true">on.</get>
</string-list>
<!-- add an element -->
<string-list list="one,two,three" resultproperty="list.added">
<add>four</add>
</string-list>
<!-- remove an element -->
<string-list list="one,two,three" resultproperty="list.removed">
<remove>three</remove>
</string-list>
<echo>
number elements: ${list.size}
contains one?: ${contains.one}
first num: ${list.zeroth}
get pattern.: ${list.get.regex}
reversed: ${list.reversed}
add an element: ${list.added}
remove an element: ${list.removed}
</echo>
results would look like:
number elements: 3
contains one?: true
first num: one
get pattern: one
reversed: two,three,one
add an element: one,two,three,four
remove an element: one,two



