Title: Did you know that in a string you can replace a text with a new one with a different length by using the C$REPLACE_ALL routine?

Usually to replace a text into a string you can use the "inspect replacing" statement. But, with this kind of approach, the original text and the new text must have the same length.
To avoid this problem you can use the "C$REPLACE_ALL" routine.
This routine uses the "regular expression" syntax in the search string and in the replace string

  call "C$REPLACE_ALL" using wrk-str 
                             search-string 
                             replace-string
                             crep-right-trimmed 
                             w-error
                      giving wstatus

Where:
"wrk-str" is the variable that contains the string to manage, and before the execution of the routine it contains the original text, while after the execution it contains the new text.
"search-string" is a variable that contains the "regular expression" used to find the text to be replaced.
"replace-string" is a variable that contains the "regular expression" for the new text.
"crep-right-trimmed" is a constant used to change the behavior of the routine. The possible value can be "CREP_CASE_INSENSITIVE", "CREP_LEFT_TRIMMED" and "CREP_RIGHT_TRIMMED"
"w-error" is a variable that contains the error description if there is one.
"wstatus" is a variable that contains the status of the execution.

For example, to change the string "Today is a rainy day" to "Today is a very sunny day"

  move "Today is a rainy day"   to wrk-str
  call "C$REPLACE-ALL" using wrk-str 
                             "rainy"
                             "very sunny"
                             crep-right-trimmed 
                             w-error
                      giving wstatus
Authored by: Veryant Support on Wed, Jun 29th, 2016 at 7:00 PM
This question has been viewed 2146 times so far.
Online URL: http://support.veryant.com/support/phpkb/question.php?ID=276

Powered by PHPKB Knowledge Base Software