parse a line into fields
Robert Brenstein
rjb at robelko.com
Fri Aug 26 12:43:44 EDT 2005
>Quoting Robert Brenstein <rjb at robelko.com>:
>Hi there
>>
>>Bob, to make sure what's going on make a button with a following script
>>
>>put "theNameOfYourField" into f -- insert your field name here
>>put empty into v
>>get line (the hilitedlines of fld f) of fld f -- or just get line 1
>>repeat for each char i in it
>> if chartonum(i)<32 then -- control character
>> put "[" & chartonum(i) & "]" after v
>> else if chartonum(i)>126 then -- high-ascii
>> put "[" & chartonum(i) & slash & i & "]" after v
>> else -- normal character
>> put i after v
>> end if
>>end repeat
>>answer v
>
>OK it is now clearer
>
>The lines look like
>[0][6]oppn[0][0][0][2]date[0][0][0][3]etc etc
>
>In other words... The data items are not in brackets.
>
>So the data items are chartonum >126
>
>I assume it could be parsed per line by taking
>only the items without a bounding
>[]. I could then for example set the item
>delimiter to ], ignore the item if it
>starts with [ ?
>
>Would that work?
>
>All the best
>bob
No. Items with chartonum over 126 would include
the actual character after slash. For example,
[138/ä]. The numbers in square brackets are ascii
values of the control characters that you have.
The bottom line of this exercise is that your
squares are different control characters not a
single one.
How to proceed depends on a few things. Somehow,
it seems to me that the data from the database is
not really binary. If so, you can read it as text
and Rev's engine will strip all the null
characters for you. Then you can replace the
remaining control characters with tabs like
follows:
get url ("file://" & filePath)
replace numtochar(6) with tab in it
replace numtochar(2) with tab in it
replace numtochar(3) with tab in it
It seems that there is a single non-null control
character between each item, so the result will
display nicely in a field with tabstops set
accordingly. Should you get duplicate tabs, you
could reduce them with
replace tab&tab with tab in it
Robert
More information about the use-livecode
mailing list