How to replace a text within a string with a different length of text.
Usually to replace a text in a string you 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 both the search string and the replace string.
Here's the syntax for C$REPLACE_ALL:
call "C$REPLACE_ALL" using wrk-str
"wrk-str" contains the full string passed and returned from the routine.
"search-string" is 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
by: Veryant Support
This question has been viewed 4181 times so far.
Here to View all the questions in isCOBOL General
There are no attachment file(s) related to this question.
There are no user comments for this question. Be the first to post a comment. Click Here