Hello All,
I am using text morphs which may contain extended ascii characters (in my case spanish characters 'ñáéíóú'). When I save those morphs and bring them back to screen everything works fine. My problem comes when I write the morphs contents to a plain .txt file (which in my case has to be opened with TextEdit in Mac Osx). In that case the special characters are expanded into several. I am working with Squeak 3.9 in Mac OsX. I have tried UTF8TextConverter but I am obviously doing something wrong (My knowledge of this issue is really scarce) . My code can be sumarized with this snippet. tm := TextMorph new openInHand. (I write inside the morph some text contaning special chars, such as 'bañándose') (Then I write it to a file) utfString := (tm contents string) convertToWithConverter: (UTF8TextConverter new). aFile:= CrLfFileStream forceNewFileNamed: './myfile.txt'. aFile nextPutAll: utfString. aFile close. And that's it. When I open the file in TextEdit I get 'ba√ɬ±√ɬ°ndose'. I have tried out some other bizarre strategies but they dont work either :-( Thanks very much for your help, Javier |
Am 08.09.2008 um 14:15 schrieb Javier Reyes: > Hello All, > I am using text morphs which may contain extended ascii characters > (in my case spanish characters 'ñáéíóú'). When I save those > morphs and bring them back to screen everything works fine. My > problem comes when I write the morphs contents to a plain .txt file > (which in my case has to be opened with TextEdit in Mac Osx). In > that case the special characters are expanded into several. > > I am working with Squeak 3.9 in Mac OsX. I have tried > UTF8TextConverter but I am obviously doing something wrong (My > knowledge of this issue is really scarce) . My code can be sumarized > with this snippet. > > > tm := TextMorph new openInHand. > (I write inside the morph some text contaning special chars, such as > 'bañándose') > > (Then I write it to a file) > utfString := (tm contents string) convertToWithConverter: > (UTF8TextConverter new). > aFile:= CrLfFileStream forceNewFileNamed: './myfile.txt'. > aFile nextPutAll: utfString. > aFile close. > > And that's it. When I open the file in TextEdit I get 'ba√ɬ > ±√ɬ°ndose'. I have tried out some other bizarre strategies > but they dont work either :-( > > Thanks very much for your help, TextEdit tries to guess the encoding and often gets it wrong. You can set the encoding it uses in its preferences. And this code f := FileStream forceNewFileNamed: 'myfile.txt'. f nextPutAll: 'bañándose'. f close works just fine for me, it produces utf8-encoded text. (you should not use CrLfStream anymore) - Bert - |
Thanks so much Bert!
I was pointing in the wrong direction ! I have changed the textedit preferences and it works perfectly. All the best, Javier
On Mon, Sep 8, 2008 at 2:54 PM, Bert Freudenberg <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |