View previous topic :: View next topic
|
Author |
Message |
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi All,
I have a requirement which needs to check a char in a string and instead of that char i need to replace with a string. is it possible by using INSPECT REPLACING function.
For Ex:
i am having a string like:
ABCD&EFGG
i want the output like below after replacing & with &:
ABCD&EFGG.
same thing i want for the characters
< to <
> to >
' to '
" to "
Please help me on this.
Thanks in Advance.
Regards,
Nath. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
is it possible by using INSPECT REPLACING function. |
manuals are found with the buttons at top of page. why don't you look up the inspect command in a cobol manual and see what you can do? |
|
Back to top |
|
|
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi dbzTHEdinosauer,
i checked the manuals. but i didn't found related to my requirement. There is only have example for same length of string replacing. mine is not in that case. so please help me if you/anybody knows on this..
Thanks,
Nath. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
ok, you now know that inspect does a one to one replacement.
you could use inspect to determine if any of the sub-strings are present in the input string and require replacement.
Then you could walk thru with either an index (if you declare the input string as a table consisting of single char) or use reference modification to move the input to the output, testing constantly if the input field is a sub-string that requires replacement. |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
rguhanath,
You can try this piece of code:
Code: |
WORKING STORAGE
01 I PIC 9(02) VALUE 1.
01 KT PIC 9(02) VALUE 1.
01 WS-A1 PIC X(05) VALUE '&'.
01 WS-A2 PIC X(03) VALUE '<'.
01 WS-A3 PIC X(03) VALUE '>'.
01 WS-A PIC X(80) VALUE SPACES.
01 INPUT-FIELD PIC X(1) VALUE SPACES.
88 A-1 VALUE '&'.
88 A-2 VALUE '<'.
88 A-3 VALUE '>'.
PROCEDURE DIVISION
PERFORM UNTIL I = LENGTH OF A
MOVE A(I:1) TO INPUT-FIELD
EVALUATE TRUE
WHEN A-1
MOVE WS-A1 TO WS-A(KT:5)
COMPUTE KT = KT + 5
WHEN A-2
MOVE WS-A2 TO WS-A(KT:3)
COMPUTE KT = KT + 3
WHEN A-3
MOVE WS-A3 TO WS-A(KT:3)
COMPUTE KT = KT + 3
WHEN OTHER
MOVE A(I:1) TO WS-A(KT:1)
COMPUTE KT = KT + 1
END-EVALUATE
COMPUTE I = I + 1
END-PERFORM |
Quote: |
INPUT A:9999&99999<999999>99999999&
OUTPUT WS-A:9999&99999<999999>99999999& |
Similarly you can test for other conditions as well.
Do remember that your output field should be big enough to accomodate the replacements.
WTF |
|
Back to top |
|
|
rguhanath
New User
Joined: 16 Oct 2006 Posts: 81 Location: chennai
|
|
|
|
Hi Succor,
i have tried this piece of code and its working fine.. Thanks a lot...
-Nath |
|
Back to top |
|
|
|