对一个简单的字符串模板进行的测试
2016-10-23 15:43
337 查看
对一个简单的字符串模板进行的测试
package mytest;
import java.util.Iterator;
import java.util.Properties;
public class Template {
public String composeMessage(String template,Properties data) throws Exception{
Iterator it =data.entrySet().iterator();
while(it.hasNext()){
Object o=it.next();
template=template.replaceFirst("\\$\\{"+o.toString().split("=")[0]+"}", o.toString().split("=")[1]);
}
return template;
}
public static void main(String[] args) {
String template="尊敬的客户${customerName}你好!本次消费金额${amount},您帐户${accountNumber}上的余额为${balance}";
Properties p=new Properties();
p.put("customerName", "zhangsan");
p.put("amount", "1111");
p.put("accountNumber", "123");
p.put("balance", "0");
try {
System.out.println(new Template().composeMessage(template,p));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package mytest;
import java.util.Iterator;
import java.util.Properties;
public class Template {
public String composeMessage(String template,Properties data) throws Exception{
Iterator it =data.entrySet().iterator();
while(it.hasNext()){
Object o=it.next();
template=template.replaceFirst("\\$\\{"+o.toString().split("=")[0]+"}", o.toString().split("=")[1]);
}
return template;
}
public static void main(String[] args) {
String template="尊敬的客户${customerName}你好!本次消费金额${amount},您帐户${accountNumber}上的余额为${balance}";
Properties p=new Properties();
p.put("customerName", "zhangsan");
p.put("amount", "1111");
p.put("accountNumber", "123");
p.put("balance", "0");
try {
System.out.println(new Template().composeMessage(template,p));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
相关文章推荐
- 在Eclipse下,采用mulan多标签分类软件进行一个简单的测试实验
- x-template:一个简单高效的字符串模板引擎
- 写一个函数,完成内存移动,并为其写一个简单的测试用例来进行测试
- 目前大家对Python都有一个共识,就是他对测试非常有用,自动化测试里Python用途也很广,但是Python到底怎么进行自动化测试呢?今天就简单的向大家介绍一下怎么使用Python进行自动化测试
- x-template:一个简单高效的字符串模板引擎
- 使用jmeter进行接口压力测试的一个简单例子
- (1)写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”); (2)编写单元测试进行测试; (3)用ElcEmma查看代码覆盖率,要求覆盖率达到100%。
- 一行代码实现一个简单的模板字符串替换
- 使用Java在本地创建一个服务器 ,通过浏览器对其进行访问的一个简单测试
- 一个简单的linux的测试修改模板
- 对一个字符串进行简单加密
- 写一个函数,完成内存移动,并为其写一个简单的测试用例来进行测试
- 用正则进行字符串切分的一个应用
- 一个简单的日志类,测试时候用
- J2EE学习笔记二:配置一个简单的J2EE测试环境
- C# 一个简单分词程序的思路和代码(六) 源代码 ,测试程序,词库下载地址
- 因为不想再程序中写循环,因此把UI页面需要更新的纪录的主键组成了一个以","隔开的字符串,将这个字符串传入存储过程中进行处理(转)
- 做一个简单的PHP测试页来测试是否正常
- zz 高效的中文字符串截取函数,附带一个性能测试方法Benchmark_Iterate
- OpenCms JSP 模板开发——创建一个简单的JSP模板