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: 8057
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: 8057
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 Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts Remove junk values in a file and rite... KP1125 DFSORT/ICETOOL 2 Wed Jan 25, 2017 9:58 pm


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