I am having a problem writing/creating a log file that contains non-ANSI characters. I used fileopen with $FO_UTF8_NOBOM parameter and passed it to FileWriteLine as suggested in the manual (https://www.autoitscript.com/autoit3/docs/intro/unicode.htm)
Here's my code:
#include <File.au3>
Local $hFileOpen = FileOpen($CmdLine[1], $FO_UTF8_NOBOM)
Local $sFileContent = FileRead($hFileOpen)
$LogReport = $CmdLine[2]
If _FileCreate($LogReport) = 0 Then
MsgBox(0, 'Permission Denied', 'Could not create log file')
Exit
EndIf
Local $hLogFileHandle = FileOpen($LogReport, $FO_UTF8_NOBOM)
; list of valid characters to be used in Regular Expression Pattern
$AccentedChars = "âãäåæçèéêëìíîïàñòóôõöøùúûüýÿāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥħĨĩĪīĬĭ"
$PunctuationMarks = "“”‘’'"";&_:–,\.\?\!"
$Braces = "\(\)\[\]<>"
$MathOperators = "/\-=$"
$OtherValidCharacters = "©"
; Look for non-ANSI character that is not on the list above
$asResult = StringRegExp($sFileContent, '([^0-9A-Za-z\s' & $AccentedChars & $PunctuationMarks & $Braces & $MathOperators & $OtherValidCharacters & '])++', 3)
$ListOfInvalidChars = ""
For $i = 0 to UBound($asResult)-1
If StringInStr($ListOfInvalidChars, $asResult[$i]) = 0 Then $ListOfInvalidChars = $ListOfInvalidChars & $asResult[$i]
Next
if $ListOfInvalidChars <> "" Then
;write the list of characters found into the log file, hopefully as UTF8 so I could actually see what the character was and not just a ? character
MsgBox(0, "Found", $ErrorMessage)
FileWriteLine($hLogFileHandle, $ErrorMessage)
Else
MsgBox(0, "Result", "No error")
Endif
FileClose($hLogFileHandle)
On the test file I am using, I placed a non-ANSI character. I know that it was able to detect that because of the Msgbox before writing it to the log file.
When the script is finished, the log file contains nothing.
I though it would be the Autoit version. I am using 3.3.10.2. Unicode support starts on version 3.2.4.0 so my version should be fine, right?
Any help would be appreciated.