Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 7932
Location: Bellevue, IA

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: 7932
Location: Bellevue, IA

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 Replace repeated JCL with looping REXX prino CLIST & REXX 3 Thu Oct 13, 2016 5:30 am
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
This topic is locked: you cannot edit posts or make replies. Sort card to replace text using cross... Susanta SYNCSORT 32 Tue Sep 13, 2016 4:17 pm
No new posts Replace function abdulrafi COBOL Programming 13 Mon Sep 12, 2016 10:12 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us