当前位置: 代码迷 >> J2SE >> 求教一个正则表达式(replaceall()),该如何处理
  详细解决方案

求教一个正则表达式(replaceall()),该如何处理

热度:358   发布时间:2016-04-24 15:27:35.0
求教一个正则表达式(replaceall())
String   s1= "User   ID:${id}name:${name} "
我想用replaceall()
将${id}变为001,${name}变为zhang

怎么写replaceall()的参数?

------解决方案--------------------
String s1= "User ID:${id}name:${name} ";
System.out.println(s1.replaceAll( "\\$\\{id\\} ", "001 ").replaceAll( "\\$\\{name\\} ", "zhang "));
------解决方案--------------------
String s1 = "User ID:${id}name:${name} ";
s1 = s1.replaceAll( "\\$\\{id\\} ", "001 ").replaceAll( "\\$\\{name\\} ", "zhang ");
System.out.println(s1);
------解决方案--------------------
s1.replaceAll( "\\$\\{id\\} ", "001 ").replaceAll( "\\$\\{name\\} ", "zhang ")