View previous topic :: View next topic
|
Author |
Message |
nimisanand
New User
Joined: 22 Nov 2005 Posts: 24
|
|
|
|
Hi,
I have a string which is defined as x(5000).
This string could be like this
'name1 address1 address2' etc..
The number of spaces between the words is not fixed. I would like to write this as a trailer record in my file with only one space in between each word.
Please let me know how can we achieve this.
Regards,
Nimi |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Code: |
String <field-1>
delimited by all spaces
' '
<field-2>
delimited by all spaces
into <destination field>
end-string
|
|
|
Back to top |
|
|
nimisanand
New User
Joined: 22 Nov 2005 Posts: 24
|
|
|
|
there is only variable whoes value is 'name1 address1 address2' with no fixed spaces between them.
I didnt understand field-1 field-2 |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
first you will have to unstring this variable into howevermany field-s there can be and then restring with the string logic i previously provided.
or- loop thru the variable with a subscript
and only move char > space - and when you find a space, don't move it, but set a flag that you found a space,
- and then when you find a non-space
- and the flag is set, move a space, set the flag off, and move the non-space char
- when the flag is not set, move the non-space char
- loop
|
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
nimisanand wrote: |
The number of spaces between the words is not fixed. I would like to write this as a trailer record in my file with only one space in between each word.
|
From what you wrote above it seems you want to write name and addresses in output file as one record and you want to strip-out spaces if it is more than two.
If i have understood you correctly below code will solve your requirement.
Code: |
*WS
01 VINTEMP.
02 VIN PIC X(40) VALUE 'NAME ADR1 ADR2 ADR3 '.
02 VIN1 REDEFINES VIN PIC X OCCURS 40 TIMES.
01 VOUT PIC X(40).
01 VTEMP PIC X(40).
01 PTR1 PIC 99.
01 PTR2 PIC 99.
*PD
MOVE 1 TO PTR1 PTR2.
MOVE SPACES TO VOUT VTEMP.
PERFORM UNTIL PTR1 > 40
UNSTRING VIN DELIMITED BY ALL SPACES
INTO VTEMP POINTER PTR1
STRING VTEMP DELIMITED BY SPACES
INTO VOUT POINTER PTR2
ADD 1 TO PTR2
END-PERFORM.
DISPLAY "INPUT :" VIN.
DISPLAY "OUTPUT:" VOUT.
|
Output will be
Code: |
INPUT :NAME ADR1 ADR2 ADR3
OUTPUT:NAME ADR1 ADR2 ADR3
|
Post back again if anything else than this you wanted..
|
|
Back to top |
|
|
nimisanand
New User
Joined: 22 Nov 2005 Posts: 24
|
|
|
|
unstring with pointer and string with pointer worked..thanks a lot... |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Quote: |
unstring with pointer and string with pointer worked.. |
Thanks for letting us know
U R Welcome |
|
Back to top |
|
|
|