So my idea is to count the number of commas before the key word in
the header line and then step down the record and pull the desired
field out of the record.
My second way is elegantly and uses the translate and word functions,
but the translate does have one drawback
You have to know for sure that some character would NEVER be in the
input record, here I picked the $. Use the translate function to
change all spaces to that character and at the same time translate
commas to spaces. Then you can use the word function to pull out your
value. One small snag is that two comma together become two spaces
and get treated as one and you get the wrong word.
However the changestr function can fix that by adding a space between
them. The down side is the extra if statement to change the found
value of a single blank to nothing. Assuming again you are OK with
treating a single blank for your value as missing.
I wrote the statements all together and did not "save" the results
rom each function as they really are only needed to validate the
statement is working, or to see earier how it works.
This first part is the same for both ways, find where the key word
is in the header line.
/* REXX */
rec ="name,phone,sex,LineAddress,city,state,zip" /* example */
numcomma = countstr(",",substr(rec,1 ,pos("LineAddress",rec,1)) )
/* count the number of commas before the line address */
Way One
/* here is an example data line */
rec = "ken,123-4567,M,123 some road,new york,ny,02345"
/* or rec = "ken,123-4567,M,,new york,ny,02345" for the missing one*/
p1 = 1
do i=1 to numcomma
p1 = pos(",",rec,p1)+1
end
address = substr(rec,p1,pos(",",rec,p1)-p1)
q = length(address)
say " address has a length of " q ", a valuse of> " address "<"
Say "Input line was " rec
It give a zero length if the value is missing
Way Two - Using the translate and the word function
rec = "ken,123-4567,M,123 some road,new york,ny,02345"
/* here is an example data line, same as above */
address =Translate(word(translate(changestr(",,",rec,", ,"),"$ "," ,")
,numcomma+1)," ","$")
if address = " " then address = ""
q = length(address)
say " address has a length of " q ", a valuse of> " address "<"
say "Input line was " rec
Enjoy
In article <
loblpb1afpaiv8fj7...@4ax.com>,
art...@munged.invalid says...