OS2 World Community Forum
OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Per E. Johannessen on April 04, 2019, 06:26:12 pm
-
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 */
---
-
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:
; 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
In REXX, this similar one should work:
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
-
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.)
-
ChangeStr is supported by Classic REXX. You just need not-to-old DLLs. (The same applies to the functions in REXXUTIL.DLL.)
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
-
Hobbes has a rexxutil.dll dated 2008.
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.
-
Anyone knows which DLL contains CHANGESTR ?
(By the way, the reason I need this "search/replace" routine is that DBExpert has trouble calculating numbers in forms on systems where locale configuration for decimal symbol is a comma.)
-
Hobbes has a rexxutil.dll dated 2008.
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.
I noticed he did include the sources if anyone some day wants to improve on the dll.
I found this interesting article on the subject.
http://www.scoug.com/os24u/2002/scoug202.changestr.html
-
CHANGESTR is an Object Rexx built-in function.
The OREXX INF help file includes a Rexx version, so you can write and call your own CHANGESTR.CMD function:
result=''
$tempx=1;
do forever
$tempy=pos(needle,haystack,$tempx)
if $tempy=0 then leave
result=result||substr(haystack,$tempx,$tempy-$tempx)||newneedle
$tempx=$tempy+length(needle)
end
result=result||substr(haystack,$tempx)
-
CHANGESTR() is also supported by KEXX in Kedit for Windows version 1.6.1.
I only learned this recently, been using TRANSLATE() since 1988:)
-
Regina has Changestr().