gpt4 book ai didi

java - 如何从 ant CSV 属性中提取第一个元素

转载 作者:行者123 更新时间:2023-11-30 07:38:55 25 4
gpt4 key购买 nike

给定一个 CSV Ant 属性,

<property name="module.list" value="mod1,mod2,mod3,mod4,mod5"/>

我怎样才能得到第一个元素(即这里的“mod1”)?我想执行一个将“mod1”作为参数之一的命令。

此外..我无法将这个原始的“module.list”属性修改为列表或其他任何东西..虽然我可以从中创建另一个列表、属性等..

任何帮助表示赞赏..谢谢

最佳答案

这是完成您所描述内容的一种方法。

  1. 将 CSV 写入临时文件
  2. replaceregexp解析它
  3. 将清理文件的内容读入新属性
  4. 删除临时文件

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com