View previous topic :: View next topic
|
Author |
Message |
vijaymfdata
New User
Joined: 20 Jun 2005 Posts: 6
|
|
|
|
Hi All,
I have a variable A=a_a______aaaaa(_ = SPACES) i need finally
A or B=a_a_aaaaa how to do this? NOTE:SPACES may not be same all the time it may be 2 or 3 or 4.. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
vijaymfdata wrote: |
I have a variable A=a_a______aaaaa(_ = SPACES) i need finally A or B=a_a_aaaaa how to do this? NOTE:SPACES may not be same all the time it may be 2 or 3 or 4.. |
Are you saying that you want to replace multiple spaces with a single space in a string? |
|
Back to top |
|
|
vijaymfdata
New User
Joined: 20 Jun 2005 Posts: 6
|
|
|
|
Yes |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
The simplest might be a perform loop with reference modification, increment thru the variable looking for multiple spaces and when found slide the remaining data left to eliminate them. |
|
Back to top |
|
|
vijaymfdata
New User
Joined: 20 Jun 2005 Posts: 6
|
|
|
|
Hi Thompson,
Thank you for your reply.Could you please elaborate your words,I have got broad udestanding and also im facing another problem like i have a variable of x(20) it may contain value like 'a__+.aaa--aaa@@aaa-*'(list of posiible special char i have it on array of size 5). i need final result like 'a_aaa_aaa' that is why i planned to convert all special char to spaces then to multiple spaces to single space is this the right way.
Please ask if you need any clarification on this
Regards
Vijay |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
vijaymfdata wrote: |
Thank you for your reply.Could you please elaborate your words,I have got broad udestanding and also im facing another problem like i have a variable of x(20) it may contain value like 'a__+.aaa--aaa@@aaa-*'(list of posiible special char i have it on array of size 5). i need final result like 'a_aaa_aaa' that is why i planned to convert all special char to spaces then to multiple spaces to single space is this the right way. |
instead of
Code: |
if area(i:2) = spaces |
you could
Code: |
if area(i:1) = bad(1)
or bad(2)
or bad(3)
or bad(4)
or bad(5) and
area(i+1:1) = bad(1)
or bad(2)
or bad(3)
or bad(4)
or bad(5) |
while you increment thru the variable. |
|
Back to top |
|
|
Shanu.sukoor
New User
Joined: 31 Jan 2006 Posts: 32 Location: India
|
|
|
|
Another solution
Redefine the string with occurs class having PIC value X(1). Perform a para for each character with the following logic
In the para have an indicator which will indicate whether a space has been written for the previous bad character( _ @ $%^..)
Move valid character to a new string whenever you meet it.
Whenever u meet a bad data move a space and set the indicator. Do not move any space for bad data if you the indicator is already set. Reset the indicator whenever you meet a valid data.
Please let me if you are gonna try this!! |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Shanu.sukoor wrote: |
Another solution
Redefine the string with occurs class having PIC value X(1). Perform a para for each character with the following logic |
Retro, boy, that's what RM freed us from.....
Young'ns, old is new and new is old.....grumble....grumble.... |
|
Back to top |
|
|
vijaymfdata
New User
Joined: 20 Jun 2005 Posts: 6
|
|
|
|
U r logic will work for single char comparision.consider following example
'A=aa++aa___aaPLUSaaMINUSaaBLANKaa' then i need A=aa_aa_aa_aa_aa_aa (here PLUS,MINUS,BLANK,+,_*.... are possible special char.all possible special chars are in an array) |
|
Back to top |
|
|
chaudhary1984
New User
Joined: 03 Oct 2006 Posts: 5
|
|
|
|
what is difference between buffer & buffer space? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
I believe this should start a new topic - it does not appear to be related to the current thread.
When you want to ask a new question please do not use "reply" to an existing topic, but rather use "new topic" and you will get more and better replies.
In answer to your buffer question, they are both the "same" thing - some amount of memory typically used to improve i/o performance (there can be other buffers, but i/o is one of the most common). For example, when your program "reads" blocked input, usually it is a transfer from a buffer rather than a physical read of the device. Another way to think of it is that the buffer is where the i/o takes place and buffer space is the memory allocated for the buffer. |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
vijaymfdata,
Code: |
01 WORD-LIST.
05 FILLER PIC X(10) VALUE ?- ?.
05 FILLER PIC X(10) VALUE ?+ ?.
05 FILLER PIC X(10) VALUE ?PLUS ?.
05 FILLER PIC X(10) VALUE ?MINUS ?.
05 FILLER PIC X(10) VALUE ?% ?.
01 WORD-TABLE RTEDEFINES WORD-LIST.
05 SPECIAL-WORD PIC X(10) OCCURS 5 TIMES.
|
Is this correct? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Kinda funny, I just ran into a situation where I needed to remove certain junk from a buffer area. I whipped this routine up to do just that:
Code: |
MOVE ZERO TO T
PERFORM TEST AFTER
VARYING F FROM 1 BY 1
UNTIL F > W00-DATALENGTH
COMPUTE T = T + 1
* CDATA - What they were
IF W00-MSGBUFFER(F:1) = X'4C' AND
W00-MSGBUFFER(F:9) = X'4C4F4AC3C4C1E3C14A'
COMPUTE F = F + 9
END-IF
* CDATA - What they might be
IF W00-MSGBUFFER(F:1) = X'4C' AND
W00-MSGBUFFER(F:9) = X'4C5AADC3C4C1E3C1AD'
COMPUTE F = F + 9
END-IF
* CDATA - What they were
IF W00-MSGBUFFER(F:1) = X'5A' AND
W00-MSGBUFFER(F:3) = X'5A5A6E'
COMPUTE F = F + 3
END-IF
* CDATA - What they might be
IF W00-MSGBUFFER(F:1) = X'BD' AND
W00-MSGBUFFER(F:3) = X'BDBD6E'
COMPUTE F = F + 3
END-IF
* Imbeded leading spaces
IF W00-MSGBUFFER(F - 1:2) = X'6E40'
PERFORM UNTIL W00-MSGBUFFER(F:1) NOT = X'40'
COMPUTE F = F + 1
END-PERFORM
END-IF
*
MOVE W00-MSGBUFFER(F:1) TO W00-MSGBUFFER(T:1)
END-PERFORM
MOVE T TO W00-DATALENGTH |
Surprisingly it works quite well. The two compares, the first for one byte and the second for the string in question was done because I know the first would produce a CLI (which would be false almost all the time) which will execute faster than the CLC generated by the second. |
|
Back to top |
|
|
|