View previous topic :: View next topic |
Author |
Message |
anbesivam Beginner
Joined: 09 Aug 2006 Posts: 66 Topics: 14
|
Posted: Wed Nov 15, 2006 10:50 am Post subject: In between space - PL/1 |
|
|
I am having following requirement.
Code: | The string 'XXX XXXXX' should be changed as 'XXXXXXXX' --> In between two strings space is removed. |
This can be possible through some three or four line of code. But
is there any way to do this using any of the PL/1 builtin function or combination of builtin functons in one line?
Kindly let me know. |
|
Back to top |
|
|
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Thu Nov 16, 2006 2:28 am Post subject: |
|
|
anbesivam,
Try this code:
Code: |
DCL TRANSLATE BUILTIN;
DCL X CHAR(09) INIT('XXX XXXXX');
DCL Y CHAR(09) INIT('XXXXXXXXX');
DCL Z CHAR(09) INIT('XXX XXXXX');
DCL Q CHAR(08) INIT(' ');
Q = TRANSLATE(X,Y,Z);
PUT SKIP LIST('Q IS:',Q);
Q IS: XXXXXXXX
|
_________________ Shekar
Grow Technically |
|
Back to top |
|
|
bauer Intermediate
Joined: 10 Oct 2003 Posts: 315 Topics: 49 Location: Germany
|
Posted: Thu Nov 16, 2006 4:24 am Post subject: |
|
|
Hi all,
my understanding of the question is: Remove any number of Spaces in a string.
So string can be ABC DEF, desired result: ABCDEF.
This doesn't solve the code of shekar123. |
|
Back to top |
|
|
anbesivam Beginner
Joined: 09 Aug 2006 Posts: 66 Topics: 14
|
Posted: Thu Nov 16, 2006 5:27 am Post subject: |
|
|
Hi shekar123,
Thanks much for your response.
Your code works fine, if the charecter is 'XXX XXXXX'.
I need to do that for follows
Code: | 'THE VALUE' ---> should be changed as 'THEVALUE'. |
Is this possible ? |
|
Back to top |
|
|
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Thu Nov 16, 2006 5:51 am Post subject: |
|
|
anbesivam,
Try this code:
Code: |
DCL TRANSLATE BUILTIN;
DCL X CHAR(09) INIT('THE VALUE');
DCL Y CHAR(09) INIT('THEVALUE ');
DCL Z CHAR(09) INIT('THE VALUE');
DCL Q CHAR(08) INIT(' ');
Q = TRANSLATE(X,Y,Z);
PUT SKIP LIST('Q IS:',Q);
Q IS: THEVALUE
|
_________________ Shekar
Grow Technically |
|
Back to top |
|
|
bauer Intermediate
Joined: 10 Oct 2003 Posts: 315 Topics: 49 Location: Germany
|
Posted: Thu Nov 16, 2006 7:50 am Post subject: |
|
|
shekar123,
and I like to do is for
Code: |
and i like to do it for
|
|
|
Back to top |
|
|
bauer Intermediate
Joined: 10 Oct 2003 Posts: 315 Topics: 49 Location: Germany
|
Posted: Thu Nov 16, 2006 10:04 am Post subject: |
|
|
anbesivam,
if you are talking about to remove only on blank which must exist and you are looking for a solution in one line, try this:
Code: |
DCL X CHAR(10) AUTO INIT('TEST 67890');
PUT SKIP EDIT(
SUBSTR(X,1,SEARCH(X,'40'X) - 1)
|| SUBSTR(X,SEARCH(X,'40'X) + 1)
) (A) ;
|
But if you are talking about to remove several blanks I agree with you, that it is necessary to write a small function.
No builtin function is abvailable to remove special bytes from a string.
regards,
bauer |
|
Back to top |
|
|
anbesivam Beginner
Joined: 09 Aug 2006 Posts: 66 Topics: 14
|
Posted: Thu Nov 16, 2006 12:15 pm Post subject: |
|
|
Hi Bauer,
Thanks much for understanding my requirement and for your solution.
As you said, My requirement is more than two strings. I also tried all the string functions available in PL1. But nothing helps me on this.
So I will go for following code.
Code: | I = INDEX(X,' ');
DO FOREVER;
IF I = 0 ! SUBSTR(X,I) = ' ' THEN LEAVE;
SUBSTR(X,I) = SUBSTR(X,I + 1);
I = INDEX(X,' ');
END;
PUT SKIP LIST('X :',X); |
Hi shaker123,
Hope I am not explained you clearly about my requirement. Really sorry about that.
Any how, Thanks for your reply. |
|
Back to top |
|
|
mayuri Beginner
Joined: 26 Aug 2006 Posts: 17 Topics: 4
|
Posted: Fri Nov 17, 2006 4:17 am Post subject: |
|
|
hi Bauer,
you can try this.
Compute the length of the input string into WS-LENGTH
PERFORM VARYING WS-I-CNT FROM 1 BY 1 UNTIL WS-CNT> WS-LENGTH
IF WS-INPUT(WS-I-CNT:1) NOT = SPACE
MOVE WS-INPUT(WS-I-CNT:1) TO WS-OUTPUT(WS-O-CNT:1)
ADD 1 TO WS-O-CNT
END-IF
END-PERFORM |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Fri Nov 17, 2006 5:52 am Post subject: |
|
|
Mayuri,
The requirement is to be met in PL/I not in COBOL. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
mayuri Beginner
Joined: 26 Aug 2006 Posts: 17 Topics: 4
|
Posted: Fri Nov 17, 2006 9:37 am Post subject: |
|
|
oh..im so sorry..i havent noticed that.. |
|
Back to top |
|
|
|
|