OS/2, eCS & ArcaOS - Technical > Programming
Rexx function changestr
Per E. Johannessen:
AFAIK the function "changestr" is not implemented in classic REXX, but seems to be supported by Object REXX.
Does anyone know about a library with this function for classic REXX, or a "workaround" to easily achieve what "changestr" does?
---
CHANGESTR(needle, haystack, newneedle)
This function was added by the ANSI-1996 standard. It replaces all occurrences of string needle in string haystack with string newneedle. Returns the haystack if needle is not found.
Examples --
changestr(‘x’,’abcx’,’d’) == abcd
changestr(‘x’,’abcc’,’d’) == abcc /* needle was not found in haystack */
---
Andreas Schnellbacher:
ChangeStr is supported by Classic REXX. You just need not-to-old DLLs. (The same applies to the functions in REXXUTIL.DLL.)
Here's my proc for E, the macro language for EPM:
--- Code: ---; Like ChangeStr in REXX.
defproc ChangeStr( Search, SourceString, Replace)
OutString = SourceString
pStart = 1
do forever
pSearch = pos( Search, OutString, pStart)
if pSearch > 0 then
OutString = delstr( OutString, pSearch, length( Search))
OutString = insertstr( Replace, OutString, pSearch - 1)
pStart = pSearch + length( Replace)
else
leave
endif
enddo
return OutString
--- End code ---
In REXX, this similar one should work:
--- Code: ---ChangeStr2:
parse arg Search, SourceString, Replace
OutString = SourceString
pStart = 1
do forever
pSearch = pos( Search, OutString, pStart)
if pSearch > 0 then
do
OutString = delstr( OutString, pSearch, length( Search))
OutString = insert( Replace, OutString, pSearch - 1)
pStart = pSearch + length( Replace)
end
else
leave
end
return OutString
--- End code ---
Per E. Johannessen:
Thank you Andreas,
In the meantime I've tried the function "translate" and it works as needed.
I'm using the Classic REXX that comes with ArcaOS and took for granted that I had the latest DLL's.
(All the rexx dll's installed are dated 06.09.2000.)
David Graser:
--- Quote from: Andreas Schnellbacher on April 04, 2019, 07:48:13 pm ---ChangeStr is supported by Classic REXX. You just need not-to-old DLLs. (The same applies to the functions in REXXUTIL.DLL.)
--- End quote ---
Hobbes has a rexxutil.dll dated 2008. ArcaOS's dll is dated 2000.
http://hobbes.nmsu.edu/download/pub/os2/dev/rexx/rexxutil.zip
You might want to check here for anything you can use.
http://hobbes.nmsu.edu/h-browse.php?button=Browse&dir=%2Fpub%2Fos2%2Fdev%2Fdll&sort=date
Andreas Schnellbacher:
--- Quote from: David Graser on April 04, 2019, 09:52:00 pm ---Hobbes has a rexxutil.dll dated 2008.
--- End quote ---
That's Mike Green's valuable version of a OSS REXXUTIL clone.
Additionally, CHANGESTR is not defined in REXXUTIL.DLL. BTW: One difference of TRANSLATE and CHANGESTR is that TRANSLATE operates on characters and CHANGESTR on strings of any length.
Navigation
[0] Message Index
[#] Next page
Go to full version