没有合适的资源?快使用搜索试试~ 我知道了~
map中的值替换掉字符串中的变量(含运算)
3星 · 超过75%的资源 需积分: 34 11 下载量 193 浏览量
2011-02-28
10:11:08
上传
评论
收藏 1KB TXT 举报
温馨提示
试读
2页
map中的值替换掉字符串中的变量(含运算)
资源推荐
资源详情
资源评论
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.text.StrSubstitutor;
import bsh.Interpreter;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Test t = new Test();
Map map = new HashMap();
map.put("N1", new Integer(1));
map.put("N2", new Integer(2));
map.put("N3", new Integer(3));
map.put("N4", new Integer(4));
map.put("N5", new Integer(22));
map.put("N6", new Integer(6));
String str = "ÄãºÃ$${${N5}+${N6}-${N4}}";
StrSubstitutor strSubstitutor = new StrSubstitutor(map);
String result = t.operateVariable(strSubstitutor.replace(str),map);
System.out.print(result);
}
public String operateVariable(String str ,Map map){
String result = "";
int begin = 0;
import java.util.Map;
import org.apache.commons.lang.text.StrSubstitutor;
import bsh.Interpreter;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Test t = new Test();
Map map = new HashMap();
map.put("N1", new Integer(1));
map.put("N2", new Integer(2));
map.put("N3", new Integer(3));
map.put("N4", new Integer(4));
map.put("N5", new Integer(22));
map.put("N6", new Integer(6));
String str = "ÄãºÃ$${${N5}+${N6}-${N4}}";
StrSubstitutor strSubstitutor = new StrSubstitutor(map);
String result = t.operateVariable(strSubstitutor.replace(str),map);
System.out.print(result);
}
public String operateVariable(String str ,Map map){
String result = "";
int begin = 0;
资源评论
- tu201010272012-07-31只有一个例子,而且其他网站也有。
xuchong2012
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功