How to replace part of string by position?

后端 未结 18 895
逝去的感伤
逝去的感伤 2020-11-28 04:37

I have this string: ABCDEFGHIJ

I need to replace from position 4 to position 5 with the string ZX

It will look like this: ABC

18条回答
  •  隐瞒了意图╮
    2020-11-28 05:13

    String timestamp = "2019-09-18 21.42.05.000705";
    String sub1 = timestamp.substring(0, 19).replace('.', ':'); 
    String sub2 = timestamp.substring(19, timestamp.length());
    System.out.println("Original String "+ timestamp);      
    System.out.println("Replaced Value "+ sub1+sub2);
    

提交回复
热议问题