home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windoware
/
WINDOWARE_1_6.iso
/
miscprog
/
wzall
/
wz007.txt
< prev
next >
Wrap
Text File
|
1991-01-24
|
5KB
|
108 lines
INFORMIX SOFTWARE, INC., LENEXA, KS
Wingz Technical Support Bulletin Number 007
Title: Parsing a space delimited text file
Date: January 15, 1991
The following example script allows you to parse a space delimited
text file. The script steps through the worksheet row by row, parsing
each row into columns. A new column begins each time a space is
found. To use this script, open the text file to a Wingz worksheet.
With that worksheet as the current window, execute this script from
the script menu.
Sample Text:
Text Text2 Numeric Text3 Numeric2 Date
Time
Text Text2 12345.00 Text3 67890 01/01/91
12:12:12
Text Text2 12345.00 Text3 67890 01/01/91
12:12:12
Example Script:
{ ***this is only an example with no implied warrantees***
***use at your own risk, make a backup, etc.*** }
define len,matched,left_side,right_side,
s,row,first_char,last_row
repaint off
repaint selections off
select last cell { find the last cell on sheet
}
last_row=row() { set last_row to row of the last
cell }
select range a1 { select cell a1 }
put trim(indirect(makecell(1,row()))) into makecell(1,row())
{ trim all leading,trailing and extra spaces between
columns }
len=length(indirect (makecell(col(),row()))) { length of string in
current cell }
matched=match(indirect (makecell(col(),row()))," ",1) { finds where to
}
{ separate first and second columns }
for row=1 to last_row { loop thru all rows }
while matched<>0 { a space was found }
left_side=left(indirect(makecell(col(),row())),matched-1) {
left of space }
right_side=right(indirect(makecell(col(),row())),len-matched)
{ right of space }
first_char=left(left_side,1) { first character of left_side
}
left_side=is_num(first_char) { check to see if it is a
number }
put left_side into makecell(col(),row()) { put into
current cell }
put right_side into makecell(col()+1,row())
{ put into next column, current row
}
select range makecell(col()+1,row()) { select next
column }
len=length(indirect(makecell(col(),row()))) { get length of
string }
matched=match(indirect(makecell(col(),row()))," ",1)
{ find where to separate columns }
end while { exit the while loop once it has
reached }
select range makecell(1,row()+1) { select next row, first
column }
put trim(indirect(makecell(1,row()))) into makecell(1,row())
{ trim all leading,trailing and extra spaces between
columns }
len=length(indirect (makecell(col(),row()))) { length of string
in that cell }
matched=match(indirect (makecell(col(),row()))," ",1)
{ find where to separate columns }
end for { repeat until no more rows of data }
repaint selections on
repaint on
repaint window
function is_num(num)
if (num>=char(48) and num<=char(57)) { checks the ASCII value for
num }
and exact(upper(left_side),lower(left_side))
{ compare upper and lower case of left_side }
and (contains(left_side,"-") = 0) { does not have '-'
in it }
and (contains(left_side,"/") = 0) { does not have '/'
in it }
and (contains(left_side,":") = 0) { does not have ':'
in it } { ASCII value indicates it is a number }
return value(left_side) { so return the value of the
left_side }
else return left_side { not a number, return the
string }
end if { end of check }
end function { end of function is_num }