I have a string that is dynamic i.e
[some text] [current timestamp] [some more text] [some text] [current timestamp] [some more text]
How do i substring/replace all occurrences of current timestamp as the string length keeps changing.
I have a string that is dynamic i.e
[some text] [current timestamp] [some more text] [some text] [current timestamp] [some more text]
How do i substring/replace all occurrences of current timestamp as the string length keeps changing.
You can use String.replaceAll(String regex, String replacement)
or String.replaceFirst(String regex, String replacement)
.
For example:
String text = "Pmaingi12345123312OtherTextAndSomeother124123"
text.replaceFirst("regex", "change to this text");
You can use replaceAll
method of String
class.
public String replaceAll(String regex, String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement.
The given regular expression
in your case will be the current time stamp. and replacement
could be empty string. ""
OR whatever you want to replace with.