replacement

S

sara

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?

Thanks a lot.
 
?

=?ISO-8859-1?Q?Tobias_Schr=F6er?=

Hi,
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top