View previous topic :: View next topic
|
Author |
Message |
Priti_S
New User
Joined: 18 Feb 2009 Posts: 8 Location: pune
|
|
|
|
HI,
I have the following requirement
I have an input string as ABC XYZ ABC ZZZ
I want the ouput string to be ABC XYZ ZZZ
How can i eliminate the repeating ABC in the above input string using inspect verb
TIA,
PS |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
Quote: |
How can i eliminate the repeating ABC in the above input string using inspect verb |
Inspect is probably not going to do what you want.
You need to post a more clear definition of what is needed.
Will all of the "pieces" always be 3 bytes? Is there something special about ABC or should all duplicates in a line be removed? What if there are other duplicates? There may be other considerations, but only you would know them. |
|
Back to top |
|
|
Priti_S
New User
Joined: 18 Feb 2009 Posts: 8 Location: pune
|
|
|
|
ABC is just an example... u can consider another string as
scott michelle v scott bond scott....
basically i want to count the number of scott repitting in the string...
to be more specific i want to count the number of occurences of the first word(in this case scott) in a string. |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Priti_S,
there is lot of difference in the suggested requirements in your two posts. Going by
Quote: |
to be more specific i want to count the number of occurences of the first word(in this case scott) in a string. |
You can try the following code - assuming the length of the input string be 50 bytes.
Code: |
Working storage.
01 PT1 PIC 9(02) VALUE ZEROES.
01 PTEMP-ONE PIC X(50) VALUE SPACES.
01 PTEMP.
02 PTEMP-TWO PIC X(1) OCCURS 1 TO 50 TIMES DEPENDING ON PT1.
01 SPACE-STATUS PIC X(1) VALUE 'N'.
88 NO-SPACE VALUE 'N'.
88 SPACES-FOUND VALUE 'Y'.
Procedure Division.
PERFORM UNTIL SPACES-FOUND OR I= LENGTH OF PTEMP-ONE
IF PTEMP-ONE(I:1)= SPACES
SET SPACES-FOUND TO TRUE
ELSE
MOVE I TO PT1
MOVE PTEMP-ONE(I:1) TO PTEMP-TWO(I)
END-IF
COMPUTE I = I + 1
END-PERFORM
INSPECT PTEMP-ONE TALLYING N FOR ALL PTEMP(1:PT1) |
N should give you the number of occurrences of the first word. You can work around the code two make it more efficient.
Hope it helps,
WTF |
|
Back to top |
|
|
Priti_S
New User
Joined: 18 Feb 2009 Posts: 8 Location: pune
|
|
|
|
Thanks ..... bit of changes in the above code... solved my purpose.... |
|
Back to top |
|
|
|