View previous topic :: View next topic |
Author |
Message |
dohellwithmf Beginner

Joined: 12 Jul 2007 Posts: 55 Topics: 23
|
Posted: Fri Feb 06, 2009 12:30 am Post subject: String replacement in REXX |
|
|
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 |
|
 |
superk Advanced

Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
|
Back to top |
|
 |
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Fri Feb 06, 2009 9:43 am Post subject: |
|
|
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 |
|
 |
superk Advanced

Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
Posted: Fri Feb 06, 2009 10:55 am Post subject: |
|
|
Personally, I like a quick and easy TSO/E Edit for a minor task such as this. |
|
Back to top |
|
 |
Dibakar Advanced

Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Mon Feb 09, 2009 1:08 am Post subject: |
|
|
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 |
|
 |
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Mon Feb 09, 2009 1:44 pm Post subject: |
|
|
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 |
|
 |
Dibakar Advanced

Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Mon Feb 09, 2009 11:07 pm Post subject: |
|
|
Thanks semigeezer. I didn't new the use of '(str1)' in parse. |
|
Back to top |
|
 |
|
|