Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Parsing data

 [1/6] from: office::thousand-hills::net at: 8-Oct-2001 12:56


In reading data from a file by lines, I use this code to parse and reorder the data line by line. So far -so good. The code works, but how can I make it reject the first two and last two elements in the data line, and rejoin the rest? John ----Quote--- makerow: func [s [string!] /local row] [ row: copy {<tr bordercolor="lightblue" border="3" bgcolor="snow">} foreach t parse s none [ either t = "--" [replace t "--" "0:00"] [ "" ] ;either t = "G" [replace t "G" #"^(null)" ] [ "" ] append row rejoin [ "^/" <td width="6%" align="center"><font face=arial size=2 color=black> nicetime to-time t </font></td> ] ] rejoin [row "^/" </tr>]

 [2/6] from: greggirwin:starband at: 8-Oct-2001 12:21


Hi John, << In reading data from a file by lines, I use this code to parse and reorder the data line by line. So far -so good. The code works, but how can I make it reject the first two and last two elements in the data line, and rejoin the rest? >> Will this work for you?
>> mid: func [s start len][return copy/part at s start len] >> tmp: [1 2 3 4 5 6]
== [1 2 3 4 5 6]
>> mid tmp 3 (length? tmp) - 4
== [3 4] --Gregg

 [3/6] from: office:thousand-hills at: 8-Oct-2001 19:34


At 12:21 PM 10/8/2001 -0600, Gregg wrote:
>Will this work for you? > >> mid: func [s start len][return copy/part at s start len]
<<quoted lines omitted: 3>>
>== [3 4] >--Gregg
Gregg: This looks like it is relying on a fixed length file. Here is the problem, the files being parsed are a row of times that appear in a format like this 08:45 08:53 etc.etc. Tab delimited but there are coded department data that preface the line like this: FMK L-300 6:57 7:06 7:13 7:19 7:28 7:36 L-300 FMK FMK L-300 7:29 7:38 7:45 8:00 8:08 8:12 8:15 8:24 L-300 FMK The length is a unknown variable of tab delimited time values. Does that make sense? John

 [4/6] from: greggirwin:starband at: 8-Oct-2001 20:15


Hi John, << This looks like it is relying on a fixed length file. Here is the problem, the files being parsed are a row of times that appear in a format like this 08:45 08:53 etc.etc. Tab delimited but there are coded department data that preface the line like this: FMK L-300 6:57 7:06 7:13 7:19 7:28 7:36 L-300 FMK FMK L-300 7:29 7:38 7:45 8:00 8:08 8:12 8:15 8:24 L-300 FMK The length is a unknown variable of tab delimited time values. >> OK, if I understand correctly, each *line* starts with these two items: FMK L-300 ...and ends with these two items: L-300 FMK If that is correct, then what I posted should work just fine. What I posted is hard coded to deal with 2 leading and 2 trailing items that you want to eliminate. E.g.
>> mid: func [s start len][return copy/part at s start len] >> tmp: [1 2 3 4 5 6]
== [1 2 3 4 5 6]
>> mid tmp 3 (length? tmp) - 4
== [3 4]
>> tmp: [1 2 3 4 5 6 7 8 9 10]
== [1 2 3 4 5 6 7 8 9 10]
>> mid tmp 3 (length? tmp) - 4
== [3 4 5 6 7 8] If you have a variable number of leading or trailing items then you will need to do a little more work but, once you find their locations, you can still use the mid function to extract what you want. --Gregg

 [5/6] from: office:thousand-hills at: 9-Oct-2001 11:06


Gregg: Now, when I say "variable length" -that value is unknown to the script. One line might be 20 time values, another line 10 time values -but every line starts and ends with the two fields I need removed, leaving time values only " nn:nn " tab delimited. I will let you know how this worked out. Thanks.. John At 08:15 PM 10/8/2001 -0600, you wrote:

 [6/6] from: greggirwin:starband at: 9-Oct-2001 15:01


Hi John, << Now, when I say "variable length" -that value is unknown to the script. One line might be 20 time values, another line 10 time values -but every line starts and ends with the two fields I need removed, leaving time values only " nn:nn " tab delimited. >> In that case, it should work fine. --Gregg

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted