作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
给定一个 CSV Ant 属性,
<property name="module.list" value="mod1,mod2,mod3,mod4,mod5"/>
我怎样才能得到第一个元素(即这里的“mod1”)?我想执行一个将“mod1”作为参数之一的命令。
此外..我无法将这个原始的“module.list”属性修改为列表或其他任何东西..虽然我可以从中创建另一个列表、属性等..
任何帮助表示赞赏..谢谢
最佳答案
这是完成您所描述内容的一种方法。
<target name="parse" description="Example of how to parse the module.list property to extract the first value in the CSV">
<property name="module.list" value="mod1,mod2,mod3,mod4,mod5"/>
<tempfile description="Generate a unique temporary filename for processing"
prefix="module.list" suffix="csv" destdir="${basedir}" property="tmpFile" />
<concat description="Write the value of module.list to the temporary file"
destfile="${tmpFile}">${module.list}</concat>
<replaceregexp description="filter the temporary file using the regex expression to find the first occurance of a , and all characters afer and replace with nothing"
file="${tmpFile}"
match=",.*"
replace=""
byline="true"/>
<loadresource description="read the contents of the scrubbed temporary file into the mod1 property"
property="mod1">
<file file="${tmpFile}"/>
</loadresource>
<delete description="remove the temporary file"
file="${tmpFile}" />
<!--Now you have the parsed value in the mod1 property -->
<echo message="mod1=${mod1}" />
</target>
关于java - 如何从 ant CSV 属性中提取第一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1349959/
我是一名优秀的程序员,十分优秀!