Posted: Thu Jan 29, 2004 10:59 am Post subject: formatting output in REXX
Hi....
I have raw output that looks like this:
AMP AAI MAA - ..SAB2
AMP AAI EAA - ..SAB4
AMP CRDP AJT - ..SAF2
AMP CRDP SUP - ..SAF6
The dots (.. ) in the last entry of each row are garbbage characters that I want get rid of.
I have created REXX code to format it so that each row is reformattred to look like this:
AMP AAI MAA - SAB2
AMP AAI EAA - SAB4
AMP CRDP AJT - SAF2
AMP CRDP SUP - SAF6
Basically each row contains 5 parts and Each can be a maximum of 7 characters in length. If an entry is not 7 characters in lerngth then it it s padded and left justitfied to 7 characters.
I can get the padding and left justified but the garbage characters are not being stripped off.
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
Posted: Thu Jan 29, 2004 3:19 pm Post subject:
You are translating blanks to something. Try this...
Code:
/* REXX */
line= "AMP AAI MAA - "||'0203'x||"SAB2 "
parse var line p1 p2 p3 p4 rest
valid='ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
trtable=translate(xrange('00'x,'ff'x),,valid,' ')
rest=translate(rest,' ',trtable)
say space(p1 p2 p3 p4 rest)
or if you inisist on nested functions
Code:
say space(subword(line,1,4),
translate(subword(line,5),' ',translate(xrange('00'x,'ff'x),,,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' , ' ')))
This probably could use some explaination. What you want for the final translate() is all the characters that are invalid. The function
Code:
translate(xrange('00'x,'ff'x),,valid,' ')
creates a string (translate table) wherein all valid characters are turned into blanks and all invalid ones remain. Then the final translate can be used to change the invalid characters in your string to blanks. As you can see, Rexx handles nested functions just fine, though as this example shows, it can make for some impossible to read code.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum