Author Topic: Rexx function changestr  (Read 11816 times)

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +3/-0
    • View Profile
Rexx function changestr
« 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 */
---

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Re: Rexx function changestr
« Reply #1 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.)

Here's my proc for E, the macro language for EPM:

Code: [Select]
; 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:

Code: [Select]
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

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +3/-0
    • View Profile
Re: Rexx function changestr
« Reply #2 on: April 04, 2019, 09:23:26 pm »
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

  • Hero Member
  • *****
  • Posts: 967
  • Karma: +108/-0
    • View Profile
Re: Rexx function changestr
« Reply #3 on: April 04, 2019, 09:52:00 pm »
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


« Last Edit: April 04, 2019, 09:58:21 pm by David Graser »

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Re: Rexx function changestr
« Reply #4 on: April 04, 2019, 10:12:00 pm »
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.

Per E. Johannessen

  • Sr. Member
  • ****
  • Posts: 272
  • Karma: +3/-0
    • View Profile
Re: Rexx function changestr
« Reply #5 on: April 04, 2019, 11:16:36 pm »
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.)

David Graser

  • Hero Member
  • *****
  • Posts: 967
  • Karma: +108/-0
    • View Profile
Re: Rexx function changestr
« Reply #6 on: April 04, 2019, 11:54:11 pm »
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

« Last Edit: April 04, 2019, 11:59:35 pm by David Graser »

xynixme

  • Guest
Re: Rexx function changestr
« Reply #7 on: April 05, 2019, 11:26:13 am »
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:

Code: [Select]
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)

Reksa21

  • Guest
Re: Rexx function changestr
« Reply #8 on: April 24, 2021, 04:57:47 pm »
CHANGESTR() is also supported by KEXX in Kedit for Windows version 1.6.1.

I only learned this recently, been using TRANSLATE() since 1988:)
« Last Edit: April 24, 2021, 05:01:44 pm by Andy »

Wendy Krieger

  • Newbie
  • *
  • Posts: 45
  • Karma: +6/-0
    • View Profile
Re: Rexx function changestr
« Reply #9 on: October 08, 2021, 12:06:59 pm »
Regina has Changestr().