textformat in files
textformat in files
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.
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.
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.
Ok - that is it :
So it seems that the println converts the speical chars, but not in combination with the string function ( or something else .. ) .
Code: Select all
( 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" "\228\246\252")
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:
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:
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:
this would create a file with the contents:
... later after restarting newLISP
.. 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.
Here another methods to save without ruining the non-ascci characters:
Code: Select all
(set 'mylist '( "abc" "äöü" ))
(write-file "test.txt" (mylist -1))
(append "test.txt" (mylist -1)) ; append to the file
Code: Select all
(set 'str (read-file "test.txt"))
You also could use "save" and "load" to save the programmatic representation of mylist:
Code: Select all
(save "test.txt" 'mylist)
Code: Select all
(set 'mylist '( "abc" "132\148\129" ))
Code: Select all
(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.