Replace @ by //



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Replace @ by //

Postby yogeshvalhe » Wed Sep 26, 2012 7:20 pm

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
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Replace @ by //

 

Re: Replace @ by //

Postby BillyBoyo » Thu Sep 27, 2012 2:17 pm

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
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Replace @ by //

Postby yogeshvalhe » Fri Sep 28, 2012 2:39 am

Hi Billy,

Thanks for the post. It was much closer to the actual one I have implemented in my code.
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Replace @ by //

Postby yogeshvalhe » Fri Sep 28, 2012 2:42 am

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.
yogeshvalhe
 
Posts: 22
Joined: Wed Aug 18, 2010 3:32 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post