newLISP Fan Club

Forum => newLISP newS => Topic started by: didi on March 21, 2009, 07:05:55 AM

Title: textformat in files
Post by: didi on March 21, 2009, 07:05:55 AM
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.
Title:
Post by: Lutz on March 21, 2009, 01:17:12 PM
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.
Title:
Post by: didi on March 22, 2009, 12:58:37 AM
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.
Title:
Post by: didi on March 22, 2009, 03:33:07 AM
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 .. ) .
Title:
Post by: Lutz on March 22, 2009, 05:16:56 AM
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.
Title:
Post by: didi on March 22, 2009, 12:30:42 PM
Thankyou very much - no  everything works fine  :)