-5

How to replace "current timestamp" from the list of string contains "{ts '2017-01-12 16:09:20'}", The ts value changed for each String.

Eg: //Need to replace the list of old time stamp values to current time stamp

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')");
}

desired output:

VALUES('TYPE','NW','New','New','',1,'01100',null,null,'Y','PRODUCT',null,'','',2200,2604,current timestamp,'dba',current timestamp,'dba')

VALUES('CODE','01234','DDC','DDC','',1,'01100',null,null,'Y','SD','PRODUCT','','','',2200,2603,current timestamp,'dba',current timestamp,'dba')

Ahamed Nafeel
  • 49
  • 3
  • 13
  • And what have you tried so far? Check a basic regex tutorial. – f1sh Apr 26 '17 at 08:39
  • 1
    SO is a questions and answers site and not please do my work – freedev Apr 26 '17 at 08:40
  • You can start checking this method: [`String replaceAll( , )`](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#replaceAll-java.lang.String-java.lang.String-) and check a basic Regex tutorial. There are also various questions on that method. – KarelG Apr 26 '17 at 08:42

1 Answers1

0

You can try someting like this:

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')");
}
Bak
  • 161
  • 2
  • 11
  • The list not contain only two string values it contain 200. You cannot replace by put the ts value in all the 200. I need a replace method to set the value. – Ahamed Nafeel Apr 28 '17 at 04:26