ant修改文件中的内容 replace命令的使用
来源:互联网 发布:安卓5.0源码下载 编辑:程序博客网 时间:2024/05/16 05:29
一、replace命令
<replacefilter token="@MIDLET@" value="${app.midlet}"/>
<replacefilter token="@JAR@" value="${app.project}"/>
<replacefilter token="@FILESIZE@" value="${size}"/>
<replacefilter token="@DESCRIPTION@" value="${app.description}"/>
上面的replace命令用起来很简单,但没有办法做正则匹配,如果要替换的字符串,是需要用正则来描述的,可以用replaceregexp
<replaceregexp byline="true">
<regexp pattern="[1-9][0-9]{4,}"/>
<substitution expression="6356351"/>
<fileset file="test.html"/>
</replaceregexp>
<replaceregexp byline="true">
<regexp pattern="[1-9][0-9]{4,}"/>
<substitution expression="6356351"/>
<fileset file="test.html"/>
byline="true" 表示替换所有满足条件的字符串,若设为false,则只会替换第一个满足正则表达式的字符串
pattern="[1-9][0-9]{4,}"表示QQ号码的正则表达式,当然,你也可以根据需求,替换成其他正则表达式
expression="6356351" 表示将满足条件字符串替换成6356351
<fileset file="test.html"/> 表示在test.html这个文件中进行查找和替换,你也可以设置为查找多个文件,具体方法请在网上搜索fileset 的相关配置
A.替换某一文件中的字符串
<property name="temp.newstring" value="hello world" />
<replace file ="base/testing.txt" token="@temp@" value="${temp.newstring}" />
解释:token是需要替换的标记;value是新值,将testing.txt文件中的@temp@替换为hello world。
B.替换某个文件夹中存在特定标记(@CHARSET@)的文件
<property name="webapp.charset" value="UTF-8" />
<replace dir="temp" token="@CHARSET@" value="${webapp.charset}"/>
解释:查询temp目录中的所有文件,将文件中存在@CHARSET@标记的内容替换为${webapp.charset}变量值。
C.批量替换
<replace dir="dist" includes="${app.project}.jad" encoding="UTF-8">
<replacefilter token="@NAME@" value="${app.name}"/>
<replacefilter token="@VENDOR@" value="${app.vendor}"/>
<replacefilter token="@PRICE@" value="${app.price}"/>
</replace>
二、replaceregexp命令
例子:
</replaceregexp>
作用:将test.html中的QQ号码替换成6356351这串数字
- ant修改文件中的内容 replace命令的使用
- ant修改文件中的内容
- ant修改文件中的内容
- ant replace的使用
- ant replace命令 Test
- ant replace命令 Test
- android使用ant自动打包(包括更改文件中的内容)
- android使用ant自动打包(包括更改文件中的内容)
- 基于命令的批量修改文件内容
- 基于命令的批量修改文件内容
- 基于命令的批量修改文件内容
- 基于命令的批量修改文件内容
- 基于命令的批量修改文件内容
- ant的高级使用,ant命令详解,ant打包,ant编译后打包去掉jar文件
- 用Replace命令替换正在使用的文件
- ant的replace用法
- 修改文件内容 vi命令
- Linux修改文件内容【命令】
- 原创伪c代码实现线程池
- python中cursor操作数据库
- Oracle impdp 数据泵导入
- 对于MVVM大家觉得如何?过来聊聊
- webpy学习笔记之一
- ant修改文件中的内容 replace命令的使用
- Android :layer-list的用法
- Python 正则表达式提取URL中的Path
- 【Unity3D自学记录】利用代码修改图片属性(Inspector)
- 一些总结:图片太大能显示问题解决 Bitmap 、oom、Imagerloaderconfig、getclass
- Python中sort以及sorted函数初探
- 重定向输出流实现程序日志
- 如何在圆内随机点坐标
- 【2014/10/24】mysql grant revoke