Page 1 of 1

Replace @ by //

PostPosted: Wed Sep 26, 2012 7:20 pm
by yogeshvalhe
Hello,

I have requirement, in which email id should be formatted.
e.g. someone_else@website.com should become someone=else//website.com

To say, '_' should be replaced by '=' and '@' should be replaced by '//'.

I can use CONVERTING or REPLACING along with INSPECT verb in COBOL, and it allows me to replace '_' by '='.
But for '@' by '//', it is not allowing, as one position (@) is getting replaced by two positions (//).

Is there any workaround to replace/convert one position by two positions?

Tks,
YV

Re: Replace @ by //

PostPosted: Thu Sep 27, 2012 2:17 pm
by BillyBoyo
If you use UNSTRING to split on the "@" (which will always be present, and only once, in a "valid format" e-mail address - are they all valid in format?) then you can use STRING to put it back together:

UNSTRING original-email-address
  DELIMITED BY at-sign
    INTO first-part-of-email-address
         second-part-of-email-address

STRING first-part-of-email-address
       replacement-for-at-sign
       second-part-of-email-address
  INTO amended-email-address

Re: Replace @ by //

PostPosted: Fri Sep 28, 2012 2:39 am
by yogeshvalhe
Hi Billy,

Thanks for the post. It was much closer to the actual one I have implemented in my code.

Re: Replace @ by //

PostPosted: Fri Sep 28, 2012 2:42 am
by yogeshvalhe
UNSTRING WS-EMAIL-ADR DELIMITED BY '@'
INTO PART1-USER-ID
PART2-DOMAIN
END-UNSTRING.


MOVE SPACES TO WS-EMAIL-ADR.

INSPECT PART1-USER-ID REPLACING ALL '_' BY '='.

STRING PART1-USER-ID DELIMITED BY SPACE
AT-SIGN DELIMITED BY SIZE
PART2-DOMAIN DELIMITED BY SPACE
INTO WS-EMAIL-ADR
END-STRING.