Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Translate to replace the string characters

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
harishch_ch

New User


Joined: 07 Jan 2008
Posts: 27
Location: bangalore

PostPosted: Wed Feb 04, 2009 4:09 pm    Post subject: Translate to replace the string characters
Reply with quote

Hi,

I want to replace a string "xyz" with "abc" using translate and i proceeded in the below manner:

N = '343x324xyz'

TRANSLATE(N, 'abc','xyz')

o/p is: 343a324abc

I want only 'xyz' to be replaced with 'abc'.
Where as Translate is done at Character Level. i.e., 'x' replaced by 'a'

Required o/p : 343x324abc
It this possible in PL/i? and How?

Regards,
Harish
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Thu Feb 05, 2009 12:42 am    Post subject:
Reply with quote

Code:
IF INDEX(N, 'abc') > 0 THEN N = SUBSTR(N, 1, INDEX(N,'abc')-1) !! SUBSTR(N, INDEX(N,'abc')+3) ;
Untested but I do similar things in SAS all the time. If you can have more than one occurrence of the pattern in the string, you may need a DO WHILE loop.
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 456
Location: Belgium

PostPosted: Thu Feb 05, 2009 12:50 am    Post subject:
Reply with quote

??
Code:
IF INDEX(N, 'xyz') > 0 THEN N = SUBSTR(N, 1, INDEX(N,'xyz')-1) !! 'abc'!!SUBSTR(N, INDEX(N,'xyz')+3) ;
Back to top
View user's profile Send private message
donateeye
Warnings : 2

New User


Joined: 01 Jun 2007
Posts: 62
Location: chennai

PostPosted: Fri Feb 06, 2009 3:39 pm    Post subject: check this ... !!!
Reply with quote

substr(N,8,3)='abc';


this could do the trick for you....
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 456
Location: Belgium

PostPosted: Fri Feb 06, 2009 3:47 pm    Post subject:
Reply with quote

If the string to be replaced is always at the same place....
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Fri Feb 06, 2009 4:21 pm    Post subject:
Reply with quote

My assumption is that the string to be replaced can be located anywhere in the string ... hence the code.
Back to top
View user's profile Send private message
harishch_ch

New User


Joined: 07 Jan 2008
Posts: 27
Location: bangalore

PostPosted: Mon Feb 09, 2009 2:52 pm    Post subject: Reply to: Translate to replace the string characters
Reply with quote

Thanks all.. the above works fine!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts Binary to display characters Roy Ware SYNCSORT 3 Tue Sep 19, 2017 8:46 pm
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts String after '.' (period) is not copy... balaji81_k SYNCSORT 6 Wed Aug 23, 2017 9:35 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us