---Zak---
Скриптер
- Сообщения
- 455
- Репутация
- 120
Добрый день...
Есть похожая тема (http://autoit-script.ru/index.php/topic,6034.0.html), но хотелось бы увидеть подобное с помощью функции IniWriteSection.
Возьмем пример из справки:
Далее смотрим на кодировку файла - ANSI...
Возможно ли сделать все тоже самое, но с учетом кодировки UTF-8 (без BOM) ???
Создает файл в UTF-8
Так... теперь надо еще создать файл в UTF-8 (без BOM)
Добавлено:
Решил вопрос таким способом:
Источник: Functions for Ascii, Unicode, and UTF8 encoding
Есть похожая тема (http://autoit-script.ru/index.php/topic,6034.0.html), но хотелось бы увидеть подобное с помощью функции IniWriteSection.
Возьмем пример из справки:
Код:
Local $sIni = @DesktopDir & "\AutoIt-Test.ini"
; Demonstrate creating a new section using a string as input.
Local $sData = "Key1=Value1" & @LF & "Key2=Value2" & @LF & "Key3=Value3"
IniWriteSection($sIni, "Section1", $sData)
Далее смотрим на кодировку файла - ANSI...
Возможно ли сделать все тоже самое, но с учетом кодировки UTF-8 (без BOM) ???
Создает файл в UTF-8
Код:
Local $sIni = @DesktopDir & "\AutoIt-Test.ini"
FileOpen($sIni, 128+1)
; Demonstrate creating a new section using a string as input.
Local $sData = "Key1=Value1" & @LF & "Key2=Value2" & @LF & "Key3=Value3"
IniWriteSection($sIni, "Section1", $sData)
Так... теперь надо еще создать файл в UTF-8 (без BOM)
Что-то не пишет в UTF8 (без BOM) - у меня показывает ANSI256 = использовать кодировку Unicode UTF8 (без BOM) для чтения и записи.
Добавлено:
Сообщение автоматически объединено:
Решил вопрос таким способом:
Код:
Local $sIni = @DesktopDir & "\AutoIt-Test.ini"
; Demonstrate creating a new section using a string as input.
Local $sData = "Key1=1" & @LF & "Key2=фыв" & @LF & "Key3=Value"
IniWriteSection($sIni, "Section1", Unicode2Utf8(Asc2Unicode($sData)))
Func Unicode2Utf8($UniString)
If Not isBinary($UniString) Then
SetError(1)
Return $UniString
EndIf
Local $UniStringLen = StringLen($UniString)
Local $BufferLen = $UniStringLen * 2
Local $Input = DllStructCreate("byte[" & $BufferLen & "]")
Local $Output = DllStructCreate("char[" & $BufferLen & "]")
DllStructSetData($Input, 1, $UniString)
Local $Return = DllCall("kernel32.dll", "int", "WideCharToMultiByte", _
"int", 65001, _
"int", 0, _
"ptr", DllStructGetPtr($Input), _
"int", $UniStringLen / 2, _
"ptr", DllStructGetPtr($Output), _
"int", $BufferLen, _
"int", 0, _
"int", 0)
Local $Utf8String = DllStructGetData($Output, 1)
$Output = 0
$Input = 0
Return $Utf8String
EndFunc
Func Asc2Unicode($AscString, $addBOM = false)
Local $BufferSize = StringLen($AscString) * 2
Local $FullUniStr = DllStructCreate("byte[" & $BufferSize + 2 & "]")
Local $Buffer = DllStructCreate("byte[" & $BufferSize & "]", DllStructGetPtr($FullUniStr) + 2)
Local $Return = DllCall("Kernel32.dll", "int", "MultiByteToWideChar", _
"int", 0, _
"int", 0, _
"str", $AscString, _
"int", StringLen($AscString), _
"ptr", DllStructGetPtr($Buffer, 1), _
"int", $BufferSize)
DllStructSetData($FullUniStr, 1, 0xFF, 1)
DllStructSetData($FullUniStr, 1, 0xFE, 2)
If $addBOM then
Return DllStructGetData($FullUniStr, 1)
Else
Return DllStructGetData($Buffer, 1)
Endif
EndFunc
Источник: Functions for Ascii, Unicode, and UTF8 encoding