-4

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.

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
pmaingi
  • 111
  • 3
  • 14
  • you should build a regular expression that captures the timestamp you try to replace: http://stackoverflow.com/questions/3302870/how-to-parse-out-timestamp-from-this-string – Frederic Close Mar 19 '13 at 07:25

2 Answers2

0

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");
pepuch
  • 6,346
  • 7
  • 51
  • 84
0

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.

Azodious
  • 13,752
  • 1
  • 36
  • 71