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

How to replace a word in a string ?


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Mon Jan 10, 2011 10:46 pm
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: 1788
Location: Bloomington, IL

PostPosted: Mon Jan 10, 2011 10:59 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Jan 10, 2011 11:00 pm
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
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
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

Global Moderator


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

PostPosted: Tue Jan 11, 2011 1:00 am
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: 218
Location: India

PostPosted: Tue Jan 11, 2011 1:24 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


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 Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:

Back to Top