Inspect replace allows only the replacement of like sized values. I would like to find all occurances of "'" in a long string with and replace with "\'". Can anyone think of a clever approach to this?
Clive
Clive
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
...
01 IN-CURSOR PIC 999.
01 OUT-CURSOR PIC 999.
01 SEGMENT-SIZE PIC 999.
01 INPUT-AREA PIC X(something).
01 OUTPUT-AREA PIC X(somethingelse).
....
MOVE 1 to IN-CURSOR, OUT-CURSOR.
perform UNTIL IN-CURSOR > LENGTH OF INPUT-AREA
MOVE 0 TO SEGMENT-SIZE
INSPECT INPUT-AREA (IN-CURSOR:) TALLYING SEGMENT-SIZE
FOR CHARACTERS BEFORE INITIAL "'"
IF SEGMENT-SIZE > 0
STRING INPUT-AREA (IN-CURSOR:SEGMENT-SIZE)
DELIMITED BY SIZE
"\'" DELIMITED BY SIZE
INTO OUTPUT-AREA
POINTER OUT-CURSOR
ON OVERFLOW [i]handle error case[/i]
END-STRING
ELSE
STRING "\'" DELIMITED BY SIZE
INTO OUTPUT-AREA
POINTER OUT-CURSOR
ON OVERFLOW [i]handle error case[/i]
END-STRING
END-IF
ADD SEGMENT-SIZE, 1 TO IN-CURSOR
end-perform.
03 AA-A PIC S9(03).
03 AA-B PIC S9(03).
03 AA-X PIC S9(03).
03 IR-DATA PIC X(15).
03 FLD-1 PIC X(25).
03 FLD-2 PIC X(25).
MOVE +1 TO AA-A
AA-B
AA-X
MOVE IR-DATA TO FLD-1.
MOVE SPACES TO FLD-2.
PERFORM UNTIL FLD-1 = SPACES
IF FLD-1 (AA-X:) = SPACES
MOVE FLD-1(1 : AA-X - 1) TO FLD-2 (AA-B : AA-X - 1)
MOVE SPACES TO FLD-1
ELSE
IF FLD-1 (AA-X:1) = "'"
IF AA-X NOT = +1
MOVE FLD-1(1 : AA-X - 1)
TO FLD-2 (AA-B : AA-X - 1)
END-IF
COMPUTE AA-B = AA-B + AA-X - 1
MOVE "\'" TO FLD-2 (AA-B:2)
COMPUTE AA-B = AA-B + 2
MOVE FLD-1 (AA-X + 1:) TO FLD-1
MOVE +1 TO AA-X
ELSE
ADD +1 TO AA-X
END-IF
END-IF
END-PERFORM.