当前位置: 代码迷 >> J2SE >> 求教字符串替换有关问题
  详细解决方案

求教字符串替换有关问题

热度:6741   发布时间:2013-02-25 00:00:00.0
求教字符串替换问题
select a.record from phone where initTime between 2012-12-12 8:0 and 2012-12-12 8:10
select a.record from phone where initTime between 2012-12-12 8:10 and 2012-12-12 8:20
select a.record from phone where initTime between 2012-12-12 8:20 and 2012-12-12 8:30
select a.record from phone where initTime between 2012-12-12 8:30 and 2012-12-12 8:40
select a.record from phone where initTime between 2012-12-12 8:40 and 2012-12-12 8:50
select a.record from phone where initTime between 2012-12-12 8:50 and 2012-12-12 8:60
select a.record from phone where initTime between 2012-12-12 9:0 and 2012-12-12 9:10




 问下 这个 8:0我要替换成8:00  8:60 这个要替换到9:00 这些是循环出来的 要怎么做
代码:
int k = 8;
for (k = 8; k < 18; k++) {
for (int i = 0, j = 10; j <= 60; i = i + 10, j = j + 10) {

String sql = "select a.record from phone where initTime between 2012-12-12 "
+ k + ":" + i + " and 2012-12-12 " + k + ":" + j;
                
System.out.println(sql);

}
}$)","$100$2");
System.out.println(s);
String s1 = "select a.record from phone where initTime between 2012-12-12 8:50 and 2012-12-12 8:60";
Matcher m = Pattern.compile("\\s+(\\d+):60(\\s+$)").matcher(s1);
if(m.find()){
int h = Integer.parseInt(m.group(1));
s1 = s1.replaceAll("(\\s+)\\d+:60(\\s+$)", "$1"+ ++h +":00$2");
}
System.out.println(s1);
}

}

public class Test {

public static void main(String[] args) {
String s = "select a.record from phone where initTime between 2012-12-12 8:0 and 2012-12-12 8:10";
s = s.replaceAll("(\\s+\\d+:)0(\\s
  相关解决方案