replacement

Discussion in 'Java' started by sara, Dec 14, 2006.

  1. sara

    sara Guest

    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.
    sara, Dec 14, 2006
    #1
    1. Advertising

  2. 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
    =?ISO-8859-1?Q?Tobias_Schr=F6er?=, Dec 14, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Youhanna Mounir
    Replies:
    3
    Views:
    557
  2. Praveen Pandey

    replacement for ActiveX in .NET

    Praveen Pandey, Dec 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,363
    smith
    Dec 8, 2004
  3. Kermit Lowry
    Replies:
    0
    Views:
    373
    Kermit Lowry
    Sep 25, 2003
  4. mail
    Replies:
    1
    Views:
    531
    Will Stranathan
    Mar 2, 2004
  5. Dave Boland

    VB(ish) replacement

    Dave Boland, Jul 20, 2004, in forum: Perl
    Replies:
    4
    Views:
    577
    Joshua Kugler
    Sep 11, 2004
Loading...

Share This Page