如何从动态String列表中替换特定单词

时间:2017-04-26 08:37:30

标签: java regex string apache-stringutils

如何从字符串列表中替换“当前时间戳”包含“ {ts'2017-01-12 16:09:20'} ”,ts每个字符串的值都已更改。

例如://需要将旧时间戳列表替换为当前时间戳

private void replaceOldTimeStampToCurrentTimeStamp(){
    List<String>sampleString = new ArrayList<String>();
    sampleString.add("VALUES ('CODE','01234','DDC','DDC','',1,'01100',null,null,'Y','SD','PRODUCT','','','',2200,2603,{ts '2017-04-25 14:09:20'},'dba',{ts '2017-04-25 14:09:20'},'dba')");
    sampleString.add("VALUES ('TYPE','NW','New','New','',1,'01100',null,null,'Y','PRODUCT',null,'','',2200,2604,{ts '2017-01-12 16:09:20'},'dba',{ts '2017-01-12 16:09:20'},'dba')");
}

所需的输出:

VALUES( '类型', 'NW', '新', '新', '',1, '01100',NULL,NULL, 'Y', '产品',NULL, '', '', 2200,2604,当前时间戳,'dba',当前时间戳,'dba')

VALUES( 'CODE', '01234', 'DDC', 'DDC', '',1, '01100',NULL,NULL, 'Y', 'SD', 'PRODUCT', '',” ','',2200,2603,当前时间戳,'dba',当前时间戳,'dba')

1 个答案:

答案 0 :(得分:0)

你可以试试这样:

private void replaceOldTimeStampToCurrentTimeStamp(){
    String ts = "current timestamp" //the value you want, a string value
    List<String>sampleString = new ArrayList<String>();
    sampleString.add("VALUES ('CODE','01234','DDC','DDC','',1,'01100',null,null,'Y','SD','PRODUCT','','','',2200,2603,"+ts+",'dba',"+ts+",'dba')");
    sampleString.add("VALUES ('TYPE','NW','New','New','',1,'01100',null,null,'Y','PRODUCT',null,'','',2200,2604,"+ts+",'dba',"+ts+",'dba')");
}