Jump to content

Generate file with encoding UTF-8.


robierzo

Recommended Posts

Usually when I create a text file with Lisp, ANSI encoding is always displayed by default.

But I need to generate a text file whose encoding is UTF-8.

Is this possible?

thank you

Link to comment
Share on other sites

Lee, with your routine a 'Unicode' file is generated. But I need a file with UTF-8 format.

I do not need the codes. Just an empty file in UTF-8 format.

 

 

Your file with format unicode.png

I need a file with format UTF-8.png

Link to comment
Share on other sites

Example:

;; Empty UTF-8 Text File  -  Example by Lee Mac

(defun emptyutf8 ( txt / fso stm )
   (if (setq fso (vlax-create-object "scripting.filesystemobject"))
       (progn
           (vl-catch-all-apply
              '(lambda ( )
                   (setq stm (vlax-invoke fso 'createtextfile txt -1 0))
                   (vlax-invoke stm 'write (vl-list->string '(239 187 191)))
                   (vlax-invoke stm 'close)
               )
           )
           (if (= 'vla-object (type stm))
               (vlax-release-object stm)
           )
           (if (= 'vla-object (type fso))
               (vlax-release-object fso)
           )
           (findfile txt)
       )
   )
)

(defun c:test ( )
   (emptyutf8 (vl-filename-mktemp "utf.txt" (getvar 'dwgprefix)))
)

Link to comment
Share on other sites

Lee Mac. Eres un auténtico genio!!!! Te debo un litro de cerveza "estrella de Galicia". Muchas gracias.

 

Lee Mac. You're a genius !!!! I owe you a pint of beer "Estrella de Galicia". Thank you. Thank you. Thank you.....

Link to comment
Share on other sites

Hello again, Lee. I have detected an error.

The accented letters misspelled.

Example: á é í ó ú ü Á É Í Ó Ú Ü

In these cases write a symbol: �

:(:(

Link to comment
Share on other sites

I write in the file created, the following, using the command

(write-line "Autor: Roberto González Gómez. Ingeniero Técnico en Topografía\n" my_file)

But the file type: Autor: Roberto Gonz�lez G�mez. Ingeniero T�cnico en Topograf�a

Texto utf.txt

Link to comment
Share on other sites

The write-line function is designed for the ASCII character set, writing to ANSI encoded text files; in order to write to a UTF-8 encoded text file you will need to use a method similar to that demonstrated by the example code in the link I provided above, following the UTF-8 encoding standard (i.e. with some characters comprised of multiple bytes).

Link to comment
Share on other sites

Uhhhmmmm. I understand. But I see a little complicated. I will perform a function to replace accented letters by letters without accents.

I think that it will be easier. jeje

Thank Lee. Thank you so much.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...