[LISP] Writing a UNICODE character to a file - how?

[LISP] Writing a UNICODE character to a file - how?

iBlachu
Advocate Advocate
402 Views
3 Replies
Message 1 of 4

[LISP] Writing a UNICODE character to a file - how?

iBlachu
Advocate
Advocate

I am trying to write a unicode character to a file so that it is visible when I open the file.

 

(setq f (open "c:/1.txt" "w"))
(write-line (read "\"\U+00A9\"") f)
(close f)

 

I try in different ways:

(write-line "\\U+00A9" f)

(write-line "\U+00A9" f)

(write-line (read "\"\U+00A9\"") f)

 

But instead of getting an © in the file, I get \\U+00A9 all the time.

 

Anyone have any idea how to get 1 character defined by unicode in file?

0 Likes
403 Views
3 Replies
Replies (3)
Message 2 of 4

vladimir_michl
Advisor
Advisor

You can use Unicode when LISPSYS is set to 1 (since release 2021).

 

Vladimir Michl, www.arkance-systems.cz - www.cadforum.cz

 

0 Likes
Message 3 of 4

ronjonp
Advisor
Advisor

Maybe this?

(setq f (open "c:\\1.txt" "w"))
(write-line (chr 169) f)
(close f)
0 Likes
Message 4 of 4

Sea-Haven
Mentor
Mentor

Whilst (chr x) works you need to look also at what text style you have set if your reading the file for adding text.

 

Try setting Windings as current text style the text file will have a character that is not the windings character. It appears to be ignored by the  write function.

 

 

 

 

(defun c:test ( / f)
(setq f (open "D:\\acadtemp\\1.txt" "W"))
(write-line (chr 65) f)
(write-line (chr 68) f)
(write-line (chr 72) f)
(write-line (chr 169) f)
(close f)
(setq f (open "D:\\acadtemp\\1.txt" "R"))
(while (setq str (read-line f))
(princ str)
(command "text" (getpoint "\npick point ") "" str)
)
(close f)
(princ)
)
(c:test)

 

 

If you go to Windows, Fonts, "Find a character" you can work out the (chr x)

 

 

0 Likes