In Pharo 1.4 i opened a FileSystemReadStream on a text file and transformed it to a String via aFileSystemReadStream contents asString
.
My text files are UTF8 encoded and have those Windows (CR LF) linebreaks.
The resulting Pharo Strings have two linebreaks per text file line and some weird characters instead of german umlauts like Ä, Ö, Ü etc.
How can i correctly decode my text files in Pharo?
An encoding converts a sequence of code points to a sequence of bytes. An encoding is typically used when writing text to a file. To read it back in we have to know how it was encoded and decode it back into memory. A text encoding is basically a file format for text files.
Don't use FileSystemReadStreams in 1.4, they are not complete and buggy ;). Use FileStream instead.
multiByteFileStream := FileStream fileNamed: '/foo/bar.txt'.
multiByteFileStream contents.
It will return a MultiByteFileStream
where you can set the line end convention and encoding:
multiByteFileStream
"possible values are: #cr #lf #crlf"
lineEndConvention: #cr;
"set a specific converter, see subclasses of TextConverter"
converter: UTF8TextConverter new.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With