View previous topic :: View next topic
|
Author |
Message |
soundari
New User
Joined: 23 Feb 2007 Posts: 7 Location: chennai
|
|
|
|
hi,
how to replace the variable length of string in a string.
for Eg. i want to replace "ABC" by "WXYZ". it is not working by INSPECT Verb.
could you please help me in this case |
|
Back to top |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
Hi Soundari,
Quote: |
i want to replace "ABC" by "WXYZ". it is not working by INSPECT Verb
|
Inspect with replace option will only work if length of source string is equal to the destination string you want to replace with.
If you post your requirement fully, There is a possibility to solve it with some other means. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
You may need to program this yourself.
Identify the position and length of the orig string, then via STRING verb set a new var = left substring || new string || right substring, using reference modification for the substrings.
You must check that each substring exists - e.g., the left one does not if the orig string starts in pos=1. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Code: |
WS-FIRST-PART PIC X(40).
WS-REST-OF-AREA PIC X(40).
|
Code: |
INITIALIZE WS-FIRST-PART,
WS-REST-OF-AREA
UNSTRING <string>
DELIMITED BY <old-string>
INTO WS-FIRST-PART
WS-REST-OF-AREA
END-UNSTRING
IF WS-FIRST-PART = SPACES
THEN
CONTINUE
ELSE
STRING WS-FIRST-PART
DELIMITED BY SPACES
<new-string>
DELIMITED BY SIZE
WS-REST-OF-AREA
DELIMITED BY SPACES
END-STRING
END-IF
|
If your original string has embedded spaces, first do an INSPECT REPLACING ALL SPACES BY HIGH-VALUES.
Execute the above code.
INSPECT REPLACING ALL HIGH-VALUES BY SPACES. |
|
Back to top |
|
|
|