Hi,
sara schrieb:
> Hi All,
>
> I have a file for which each line has a substring monthday
> 13041140 Jun28 gh
> 130164140 Jun29 ad
> 130114540 Jun30 gg
> 1301140 Aug6 fty
> 1301140 Aug4 yy
> ....
>
> I want to convert "monthDay" part into "month-day" format, so that the
> last line will become
> 1301140 Aug-4 yy
>
> I know that there are lots of way of doing this but do you know how can
> I do this using replaceall function?
I'd suggest that you have to use regular expressions. String#replaceAll
takes a regEx, too, but replaces the matches and does no insertions.
With regEx create two groups of each line, one with the characters left
of the '-', the other with the characters right of the '-'. Then create
your new string. Your regEx pattern would be something like
([0-9]* [a-zA-Z]{3})([0-9]{1,2}.*\r\n)
HTH,
Tobi
|