MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String replacement in REXX

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
dohellwithmf
Beginner


Joined: 12 Jul 2007
Posts: 55
Topics: 23

PostPosted: Fri Feb 06, 2009 12:30 am    Post subject: String replacement in REXX Reply with quote

Hi All,

Is there any built-in function in REXX to replace one string with another. I know that there is one macro (C <str1> <str2> all) but I want to code it in my REXX tool.

Please suggest.


TIA, Mayank
Back to top
View user's profile Send private message
superk
Advanced


Joined: 19 Dec 2002
Posts: 684
Topics: 5

PostPosted: Fri Feb 06, 2009 6:12 am    Post subject: Reply with quote

4.3.43 OVERLAY
.
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Fri Feb 06, 2009 9:43 am    Post subject: Reply with quote

or if the old and new string sizes differ, you have to use a loop with either parse or substring to break off the parts you want and rejoin them. I think parse is generally faster than substr if you use it right.

OORexx (not available on MVS) has a changestr() function
_________________
New members are encouraged to read the How To Ask Questions The Smart Way FAQ at http://www.catb.org/~esr/faqs/smart-questions.html.
Back to top
View user's profile Send private message Visit poster's website
superk
Advanced


Joined: 19 Dec 2002
Posts: 684
Topics: 5

PostPosted: Fri Feb 06, 2009 10:55 am    Post subject: Reply with quote

Personally, I like a quick and easy TSO/E Edit for a minor task such as this.
Back to top
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Mon Feb 09, 2009 1:08 am    Post subject: Reply with quote

Wanted to see if this can be done by parse when the strings are variables ...

Code:
/* rexx to change all                                 
*/                                                   
a_str = 'Bond! My name is James Bond!'               
str1  = 'Bond'                                       
str2  = 'James'                                       
do forever                                           
  interpret 'parse var a_str part1' "'"str1"'" 'part2'
  if (a_str <> part1) then a_str = part1||str2||part2
  else leave                                         
end                                                   
say a_str   
Back to top
View user's profile Send private message Send e-mail
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Mon Feb 09, 2009 1:44 pm    Post subject: Reply with quote

Interpret is very inefficient. Try this instead. It runs twice as fast on my test mvs system and about 14 times faster on OORexx. I'm not sure if the speed comes from getting rid of interpret or getting rid of the long string comparison though
Code:
 a_str = "Bond! My name is James Bond!"
  str1 = "Bond"
  str2 = "James"
  Parse Var a_str part1 (str1) part2
  Do While part2 <> ""
    a_str = part1 || str2 || part2
    Parse Var a_str part1 (str1) part2
  End

_________________
New members are encouraged to read the How To Ask Questions The Smart Way FAQ at http://www.catb.org/~esr/faqs/smart-questions.html.
Back to top
View user's profile Send private message Visit poster's website
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Mon Feb 09, 2009 11:07 pm    Post subject: Reply with quote

Thanks semigeezer. I didn't new the use of '(str1)' in parse.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group