IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Translate to replace the string characters


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 05, 2009 12:42 am
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: 459
Location: Belgium

PostPosted: Thu Feb 05, 2009 12:50 am
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
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: 459
Location: Belgium

PostPosted: Fri Feb 06, 2009 3:47 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Feb 06, 2009 4:21 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Substring number between 2 characters... DFSORT/ICETOOL 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top