textformat in files

Notices and updates
Locked
didi
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

textformat in files

Post by 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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

Post by didi »

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
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

Post by didi »

Ok - that is it :

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")
So it seems that the println converts the speical chars, but not in combination with the string function ( or something else .. ) .

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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:

Code: Select all

(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:

Code: Select all

(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:

Code: Select all

(save "test.txt" 'mylist)
this would create a file with the contents:

Code: Select all

(set 'mylist '( "abc" "132\148\129" ))
... later after restarting newLISP

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.

didi
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

Post by didi »

Thankyou very much - no everything works fine :)

Locked