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
 

 

How to replace a word in a string ?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 216
Location: India

PostPosted: Mon Jan 10, 2011 10:46 pm    Post subject: How to replace a word in a string ?
Reply with quote

Hi,
I am a beginner in REXX. I have struck with a problem.

I have a string like this "T70435.USER.TEMP.SRC" and i need to change this
"T70435.USER.TEMP.CPY". Please let me know how to do this ?


Thanks,
Sri
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1753
Location: Bloomington, IL

PostPosted: Mon Jan 10, 2011 10:59 pm    Post subject:
Reply with quote

Assuming that there is some reason that you cannot use an edit macro, and that the volume of data is not so great that the (lack of) performance of EXECIO is significant, use the POS (or INDEX; I prefer POS) function find the desired sub-string, and the SUBSTR function and concatenation operator to re-assemble the string after replacement.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10232
Location: italy

PostPosted: Mon Jan 10, 2011 11:00 pm    Post subject: Reply to: How to replace a word in a string ?
Reply with quote

all depends....
fixed position, fixed length,
any position any length, one/many occurrence,
OVERLAY,POS,SUBSTR,LENGTH, || ( concatenation) are the REXX functions operators that would be used for such a task



z/OS V1R2.0-V1R10.0 TSO/E REXX User's Guide
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IKJ4C310/CCONTENTS?SHELF=IKJ4BK90&DN=SA22-7791-01&DT=20010706113306

z/OS V1R8.0-V1R10.0 TSO/E REXX Reference
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IKJ4A370/CCONTENTS?SHELF=IKJ4BK90&DN=SA22-7790-07&DT=20060626210253
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Tue Jan 11, 2011 1:00 am    Post subject: Reply to: How to replace a word in a string ?
Reply with quote

If the string was always something like a dataset name, I'd PARSE it into tokens and just swap the specific token with its replacement value, then concatenate the tokens back together.
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 216
Location: India

PostPosted: Tue Jan 11, 2011 1:24 pm    Post subject: Re: How to replace a word in a string ?
Reply with quote

sri_mf wrote:
Hi,
I am a beginner in REXX. I have struck with a problem.

I have a string like this "T70435.USER.TEMP.SRC" and i need to change this
"T70435.USER.TEMP.CPY". Please let me know how to do this ?


Thanks,
Sri


Thanks to all for the inputs.. Really usefull information to start ...

I tried a basic method.

Here is the REXX code i have coded.
Code:

MYSTR = 'T70435.USER.TEMP.SRC'   
WORD_POS=INDEX(MYSTR,'SRC')                   
SAY "WORD_POS:"WORD_POS                               
MYSTR1=OVERLAY('CPY',MYSTR,WORD_POS)         
SAY "MYSTR1:"MYSTR1                           
Back to top
View user's profile Send private message
parsesource

New User


Joined: 06 Feb 2006
Posts: 97

PostPosted: Mon Jan 17, 2011 3:13 am    Post subject: Re: How to replace a word in a string ?
Reply with quote

sri_mf wrote:
Hi,
I am a beginner in REXX. I have struck with a problem.

I have a string like this "T70435.USER.TEMP.SRC" and i need to change this
"T70435.USER.TEMP.CPY". Please let me know how to do this ?


Thanks,
Sri


not tested =>

Code:

PARSE VALUE REVERSE(DSNAME) '.'A
NEWDSNAME=REVERSE(A)!!'.CPY'
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 -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
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 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


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