shai

create text file with windows-1255 encode

16 posts in this topic

#1 ·  Posted (edited)

hi

i try to create text file with _FileCreate function that encode of this file will be "windows-1255" but i can't.
 
the file always created in utf8 encode.
 
i also tryed to do it with FileOpen($sFilePath, BitOR(2, 8))
 
and still is created in utf8 encode.
 
thanks for all your solutions.
Edited by shai

Share this post


Link to post
Share on other sites



FileWrite("FileName.txt","ANSI Content")


Regards,
 

Share this post


Link to post
Share on other sites
and still is created in utf8 encode.

What are you writing to the file?

How do you determine it's encoding eand what is the encoding exactly.. UTF8 with or without BOM?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

What are you writing to the file?

How do you determine it's encoding eand what is the encoding exactly.. UTF8 with or without BOM?

Jos

 

writing simple text to the file

when i open the txt file in notepad++ i see that file is utf8 WO BOM

Share this post


Link to post
Share on other sites
FileWrite("FileName.txt","ANSI Content")

 

its also create file on utf8 WO BOM

Share this post


Link to post
Share on other sites

writing simple text to the file

when i open the txt file in notepad++ i see that file is utf8 WO BOM

So it is a regular file and Notead++ opens it as UTF8 without bom... the new SciTE will do the same to support multibyte chaacters by default.

What is the simply text you write?

Does it contain multi-byte characters?

Show some code you use to create the file.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

even if i try this code:

FileWrite("c:\FileName.txt","ANSI Content")

the FileName.txt file is in utf8

Share this post


Link to post
Share on other sites

No it is not....  it is both ansi and utf8 without BOM as there are no special characters in there to indicate either one.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

how i can check what is the real encoding of output file?

Edited by shai

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

a/ă

Local $sFile = "FileToCheckEncoding.txt"
Local $hfOpen = FileOpen($sFile, 2 + 8)
FileWrite($hfOpen, "Đào Van Trong")
ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF)

$hfOpen = FileOpen($sFile, 2 + 8 + 32)
FileWrite($hfOpen, "UTF16 Little Endian: Đào Văn Trong")
ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF)

$hfOpen = FileOpen($sFile, 2 + 8 + 64)
FileWrite($hfOpen, "UTF16 Big Endian: Đào Văn Trong")
ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF)

$hfOpen = FileOpen($sFile, 2 + 8 + 128)
FileWrite($hfOpen, "UTF8 (with BOM): Đào Văn Trong")
ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF)

$hfOpen = FileOpen($sFile, 2 + 8 + 256)
FileWrite($hfOpen, "UTF8 (without BOM): Đào Văn Trong")
ConsoleWrite("Encoding of file " & $sFile & " is: " & _GetFileEncoding($sFile) & " - " & @extended & @CRLF)

; * -----:|
Func _GetFileEncoding($sFile)
    ; /*********************************************************************** * Trong
    ; * ---:| Function......: _GetFileEncoding($sFile)
    ; * ---:| Description...: Get File Encoding!
    ; ************************************************************************ *
    Local $sEndoding = FileGetEncoding($sFile), $sEncode
    $sEncode = $sEndoding
    If $sEndoding = 0 Then $sEndoding = "ANSI"
    If $sEndoding = 32 Then $sEndoding = "UTF16 Little Endian"
    If $sEndoding = 64 Then $sEndoding = "UTF16 Big Endian"
    If $sEndoding = 128 Then $sEndoding = "UTF8 (with BOM)"
    If $sEndoding = 256 Then $sEndoding = "UTF8 (without BOM)"
    If $sEndoding = -1 Then SetError(1, 0, -1)
    Return SetError(0, $sEncode, $sEndoding)
EndFunc   ;==>_GetFileEncoding
; * -----:|
Edit:

In Notepad++

new_docs_encoding.png

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

ok now i see that if i writing simple text is works

but if i writing text from HTTP.ResponseText object the file swich to utf8.

how i can keep the file in ansi format?

Share this post


Link to post
Share on other sites

Regards,
 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

i create this function:
Func utf8towindows1255($hFileorg, $hFiledest)
    Local $hFileOpen = FileOpen($hFileorg, 0)
    Local $sFileRead = FileRead($hFileOpen)
    FileClose($hFileOpen)
    FileClose(FileOpen($hFiledest, 2 + 8))
    Local $hfOpen = FileOpen($hFiledest, 1 + 8)
    FileWrite($hfOpen, $sFileRead)
    FileClose($hfOpen)
EndFunc
and i run it on file that is encode in utf8.
 
if i run it in my full script the output file is in utf8
but if i run it on new script with only this function the output file is in ANSI.
 
why?
Edited by shai

Share this post


Link to post
Share on other sites

Your OS Version? XP/7/8/10/x32/x64 ?
Your OS Language? English/China?
Your AutoIt Version? 3.3.6.1/3.3.8.1/3.3.10.2/3.3.12.0/3.3.13.19/AutoitCN-3.3.9.21 ?

It worked fine.

MsgBox(0,"","File Encoding is: "&utf8towindows1255("UTFFile.txt", "ansi.txt"))


Func utf8towindows1255($hFileorg, $hFiledest)
    Local $hFileOpen = FileOpen($hFileorg, 0)
    Local $sFileRead = FileRead($hFileOpen)
    FileClose($hFileOpen)
    FileClose(FileOpen($hFiledest, 2 + 8))
    Local $hfOpen = FileOpen($hFiledest, 1 + 8)
    FileWrite($hfOpen, $sFileRead)
    FileClose($hfOpen)
    Return _GetFileEncoding($hFiledest)
EndFunc

; * -----:|
Func _GetFileEncoding($sFile)
    ; /*********************************************************************** * Trong
    ; * ---:| Function......: _GetFileEncoding($sFile)
    ; * ---:| Description...: Get File Encoding!
    ; ************************************************************************ *
    Local $sEndoding = FileGetEncoding($sFile), $sEncode
    $sEncode = $sEndoding
    If $sEndoding = 0 Then $sEndoding = "ANSI"
    If $sEndoding = 32 Then $sEndoding = "UTF16 Little Endian"
    If $sEndoding = 64 Then $sEndoding = "UTF16 Big Endian"
    If $sEndoding = 128 Then $sEndoding = "UTF8 (with BOM)"
    If $sEndoding = 256 Then $sEndoding = "UTF8 (without BOM)"
    If $sEndoding = -1 Then SetError(1, 0, -1)
    Return SetError(0, $sEncode, $sEndoding)
EndFunc   ;==>_GetFileEncoding

Regards,
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now