INFORMIX SOFTWARE, INC., LENEXA, KS Wingz Technical Support Bulletin Number 008 Title: Parsing an ACSII file Date: January 15, 1991 The following example script allows you to parse an ASCII file. The script steps through the worksheet row by row, parsing each row into columns. To use this script, open the ASCII file to a Wingz worksheet. With that worksheet as the current window, execute this script from the script menu. Sample Text: "Text",12345.00,"January 12, 1991","12:12:12","555-55-5555" "Text One",1111.11,"01/01/87","01:01:01","111-11-1111" 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,row,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 } 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 or comma was found } left_side=left(indirect(makecell(col(),row())),matched-1) { left of comma } if match(left(left_side,1),"""",1) { first character is a quote } matched=match(indirect(makecell(col(),row())),"""",2) { find the end quote to match beginning quote } left_side=mid(left(indirect(makecell(col(),row())), matched-1),1,matched-2) { left_side is everything between the two quotes } right_side=right(indirect(makecell(col(),row())),len-matched-1) { right_side is to the right of the end quote and comma } else { no quote at beginning of string } left_side=is_num(left(left_side,1)) { is left_side a number } right_side=right(indirect(makecell(col(),row())),len-matched) { right side of comma } end if put left_side into makecell(col(),row()) { put left into current cell } put right_side into makecell(col()+1,row()) { everything else in next column } select range makecell(col()+1,row()) { select next column } len=length(indirect (makecell(col(),row()))) { length of string in current cell } matched=match(indirect (makecell(col(),row())),",",1) { find where to break into separate columns } end while { exit the while loop once it has reached } left_side=indirect(makecell(col(),row())) { contents of last cell on row } left_side=if(match(left(left_side,1),"""",1),mid(left_side,1,length(le ft_side)-2), is_num(left(left_side,1))) { if there are quotes, it's text, else check for value } put left_side into makecell(col(),row()) { put left_side into cell } select range makecell(1,row()+1) { select next row, first column } 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 } return value(left_side) { it is a number 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 }