[REBOL] Re: Read question in Reb 3.0
From: pwawood::gmail::com at: 20-Feb-2009 8:05
Hi Raimund
On 20 Feb 2009, at 02:56, Raimund Dold wrote:
> Hi,
>
> sorry, but it is me again.
> Your example works for the testfile I provided in the mail but
> failed on th
> e
> very next file I tested.
>
> The testfile (named testfile.dat) looks like this:
> =2D----------------------------
> "St=FCck/Nominale";"Bezeichnung"
> "4,636";"NAME"
> =2D----------------------------
>
> Just two lines to get clear results.
> If I read the file testfile.dat with the following line in R3
>
>>> dat: parse/all read %testfile.dat newline
> == ["St=FCck/Nominale" {;"Bezeichnung"} "4,636" {;"NAME"} ""
> "" "" "
> "]
>
>>> length? dat
> == 9
>
> Using parenthis around the newline gives even stranger results:
>>> dat: parse/all read %testfile.dat {newline}
> == ["St=FCck/Nominale" {;"B} "z" "" "ch" "u" {g"
> "4,636";"NAME"
>
> }]
>
>>> length? dat
> == 7
>
>>> dat/2
> == {;"B}
>
> Any more suggestions?
>
> Raimund
It seems that your data includes two field separators ";" within a
line of text and "newline" at the end of a line of text. You can
supply parse with a string of all the separators between your data:
>> parse/all read %testfile.dat join ";" newline
== ["Stock/Nominale" "Bezeichnung" "4,636" "NAME"]
In trying this out, it seems that the implicit to binary! conversion
in parse does not recognise utf-8 encoding.
>> str: {"St=F6ck/Nominale";"Bezeichnung"}
== {"St=F6ck/Nominale";"Bezeichnung"}
>> write %utest.txt to binary! str
== make port! [ .......
>> to string! read %utest.txt
== {"St=F6ck/Nominale";"Bezeichnung"}
>> parse/all read %utest.txt ";"
== ["St=C3=B6ck/Nominale" "Bezeichnung"]
Regards
Peter