textformat in files

Started by didi, March 21, 2009, 07:05:55 AM

Previous topic - Next topic

didi

After storing text in files i have sometimes the special chars eg.  "252" as backslash and decimal-sequence in the text-file where i need eg. directly the german Umlaut 'ü'  - how can i control that ?  or is it system depending ,  i use windows xp.

Lutz

#1
I assume your are using MS Windows? All ASCII under 32 and characters over 127 will be displayed in xxx form only when they are return values on the command-line. When using  'print' or 'println' to display or when loading this file into an application, the same characters will be displayed as they should in your country's locale.



If those xxx are literally in your text file, i.e. still appear when loading the file in to notepad.exe, than something was done wrong creating that file.



ps: always post questions of this nature not in the news section but in either the Windows or Unix forum topics, depending on you platform.

didi

#2
Thanks !  - and how can i move this to the windows-section ?



The thing is, that i still can see the xxx  within the editor - so i'll have a look where i did the mistake.

didi

#3
Ok -  that is it :

( set 'mylist '( "abc" "äöü" ))
( device (open "tst2.txt" "write"))
( println  ( mylist -1 ))
( println  (string mylist ))
( close (device)  )

; results to a textfile with this two lines :
;  äöü
; ("abc" "228246252")


So it seems that the println converts the speical chars, but not in combination with the string function ( or something else .. ) .

Lutz

#4
The string function converts the string literally to the xxx representation. Its supposed to do it.



Here another methods to save without ruining the non-ascci characters:


(set 'mylist '( "abc" "äöü" ))
(write-file "test.txt" (mylist -1))
(append "test.txt" (mylist -1)) ; append to the file


Your special characters will be fine. When you do a "type test.txt" in a Windows command-shell you will see "äöüäöü" on most windows systems. And you can get the whole file back in one piece:


(set 'str (read-file "test.txt"))

If you now enter: str at the prompt you will get xxx characters, but when using 'print' or 'println' on it, it will show the Umlaute.



You also could use "save" and "load" to save the programmatic representation of mylist:


(save "test.txt" 'mylist)

this would create a file with the contents:


(set 'mylist '( "abc" "132148129" ))

... later after restarting newLISP


(load "test.txt")



.. you end up with the same contents of 'mylist' in newLISP's memory as before and could do the same operations on 'mylist' as shown before with the same results.

didi

#5
Thankyou very much - no  everything works fine  :)