<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=4356</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=4356&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Как перекодировать файл из UTF8 в ANSI».]]></description>
		<lastBuildDate>Thu, 11 Aug 2016 04:25:11 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=106711#p106711</link>
			<description><![CDATA[<p>Мне такой метод не известен.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Thu, 11 Aug 2016 04:25:11 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=106711#p106711</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=106710#p106710</link>
			<description><![CDATA[<p>А вот такие символы возможно заменить иным методом, кроме как через RegexReplace?<br /></p><div class="codebox"><pre><code>msgbox % replace(&quot;ÐæẔ&quot;)

replace(data)
{
   list:={ầẦắẮằẰẵẴảẢạẠậẬấẤ:&quot;a&quot;,æÆǣǢ:&quot;ae&quot;,ßþÞ:&quot;b&quot;,ḑḐðÐḍḌḑḐ:&quot;d&quot;,ếẾềỀệỆǝƎəƏểỂễỄẹ̀Ẹ̀ɛ́ɛƐ:&quot;e&quot;,ḩḨḥḤẖ̱̲̲ḩḨ:&quot;h&quot;,ııỉỈịỊ:&quot;i&quot;,ŋŊ:&quot;n&quot;,ốỐồỒọỌớỚộỘɔƆɔ́Ɔ́ổỔỏỎ:&quot;o&quot;,œŒœ̆Œ̆:&quot;oe&quot;,ṣṢș̲̲:&quot;s&quot;,ṭṬț:&quot;t&quot;,ủỦừỪựỰụỤṳṲứỨ:&quot;u&quot;,ỹỸỳỲ̧̧̄̄:&quot;y&quot;,ẕẔ:&quot;z&quot;}
   for k,v in list
      data := RegexReplace(data, &quot;[&quot; k &quot;]&quot;, v)
   return data
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Thu, 11 Aug 2016 00:34:24 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=106710#p106710</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=100813#p100813</link>
			<description><![CDATA[<p>Одним никак, наверно, только через посредство какого-нибудь Юникода. Кстати, Latin-1 — это тоже ANSI, только не наша.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Tue, 02 Feb 2016 21:03:34 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=100813#p100813</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=100801#p100801</link>
			<description><![CDATA[<p>А как одним махом можно преобразовать ISO 8859-1 Latin 1; Western European (ISO) в Ansi?<br />У меня только через 2 преобразования получается:<br /></p><div class="codebox"><pre><code>var := &quot;Ã³&quot;
Utf8ToLatin(var)
MsgBox, % ToAnsi(var)

Utf8ToLatin(ByRef string) {
   VarSetCapacity(latin, StrPut(string, &quot;cp28591&quot;))
   StrPut(string, &amp;latin, &quot;cp28591&quot;)
   string := StrGet(&amp;latin, &quot;UTF-8&quot;)
}

ToAnsi(str)
{
    len := StrLen(str)
    VarSetCapacity(buf, len)
    prev_locale := StrGet( DllCall(&quot;msvcrt.dll\_wsetlocale&quot;, &quot;int&quot;, 0, &quot;ptr&quot;, 0, &quot;cdecl&quot;) )
    DllCall(&quot;msvcrt.dll\_wsetlocale&quot;, &quot;int&quot;, 0, &quot;str&quot;, &quot;Russian&quot;, &quot;cdecl&quot;)
    DllCall(&quot;msvcrt.dll\wcstombs&quot;, &quot;ptr&quot;, &amp;buf, &quot;str&quot;, str, &quot;ptr&quot;, len, &quot;cdecl&quot;)
    DllCall(&quot;msvcrt.dll\_wsetlocale&quot;, &quot;int&quot;, 0, &quot;str&quot;, prev_locale, &quot;cdecl&quot;)
    Return StrGet(&amp;buf, len, &quot;cp0&quot;)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Tue, 02 Feb 2016 17:40:57 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=100801#p100801</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94867#p94867</link>
			<description><![CDATA[<p>YMP, спасибо!<br /></p><div class="quotebox"><blockquote><p>А чем вам создание файла конкретно мешает? Я так понимаю, это религия?</p></blockquote></div><p>Просто этих обработок очень много - из-за этого притормаживает и не хочется ресурс SSD диска рассходовать.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Thu, 02 Jul 2015 11:12:29 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94867#p94867</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94866#p94866</link>
			<description><![CDATA[<p>Два раза можно не открывать.<br /></p><div class="codebox"><pre><code>
str := &quot;Ä&quot;
MsgBox, % Utf2Ansi(str)

Utf2Ansi(str)
{
   File := FileOpen(&quot;utf8&quot;, &quot;rw&quot;, &quot;CP0&quot;)
   File.Write(str)
   File.Pos := 0
   ansi := File.Read()
   File.Close()
   FileDelete, utf8
   Return, ansi
}
</code></pre></div><p>А чем вам создание файла конкретно мешает? Я так понимаю, это религия? <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" /> Какая-то идиосинкразия к временным файлам у народа.</p><p>Без файла можно, но тогда больше писанины.<br /></p><div class="codebox"><pre><code>
str := &quot;Ä&quot;
MsgBox, % ToAnsi(str)

ToAnsi(str)
{
    len := StrLen(str)
    VarSetCapacity(buf, len)
    prev_locale := StrGet( DllCall(&quot;msvcrt.dll\_wsetlocale&quot;, &quot;int&quot;, 0, &quot;ptr&quot;, 0, &quot;cdecl&quot;) )
    DllCall(&quot;msvcrt.dll\_wsetlocale&quot;, &quot;int&quot;, 0, &quot;str&quot;, &quot;Russian&quot;, &quot;cdecl&quot;)
    DllCall(&quot;msvcrt.dll\wcstombs&quot;, &quot;ptr&quot;, &amp;buf, &quot;str&quot;, str, &quot;ptr&quot;, len, &quot;cdecl&quot;)
    DllCall(&quot;msvcrt.dll\_wsetlocale&quot;, &quot;int&quot;, 0, &quot;str&quot;, prev_locale, &quot;cdecl&quot;)
    Return StrGet(&amp;buf, len, &quot;cp0&quot;)
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Thu, 02 Jul 2015 10:23:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94866#p94866</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94865#p94865</link>
			<description><![CDATA[<p>Так разве лучше? Все-равно файл потом как-то удалять надо.<br />Жалко, что нельзя вообще без создания файла сделать.<br /></p><div class="codebox"><pre><code>str := &quot;Ä&quot;
MsgBox, % Utf2Ansi(str)

Utf2Ansi(str)
{
   File := FileOpen(&quot;utf8&quot;, &quot;w&quot;, &quot;CP0&quot;)
   File.Write(str)
   File.Close()
   File := FileOpen(&quot;utf8&quot;, &quot;r-d&quot;, &quot;CP0&quot;)
   ansi := File.Read()
   File.Close()
   Return, ansi
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Thu, 02 Jul 2015 09:45:18 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94865#p94865</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94863#p94863</link>
			<description><![CDATA[<p>Со StrPut/StrGet не выходит, заменяется на &quot;?&quot;. Вариант через файл вполне годится. Этот файл даже на диск-то записаться не успеет, я думаю, т.е. все операции в памяти проходят. Только желательно единообразие. А то выглядит каким-то винегретом. Сначала объект используете, потом просто команды.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Thu, 02 Jul 2015 06:33:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94863#p94863</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94859#p94859</link>
			<description><![CDATA[<p>Мне надо чтобы получился результат идентичным сохранению в блокноте не ANSI символов, как ANSI.<br />То есть копируем этот символ в блокнот, сохраняем документ как ANSI.<br />Notepad сделает предупреждение, что не все символы сохранятся - мы согласимся с этим.<br />Закроем этот документ и откроем снова.<br />В результате &quot;Ä&quot; переконвертится в &quot;A&quot;.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Thu, 02 Jul 2015 01:21:02 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94859#p94859</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94858#p94858</link>
			<description><![CDATA[<p>А где у вас перекодировка? Вместо одного символа получается совсем другой.<br />В переменной str не utf-8, а utf-16. Можете конкретнее описать ситуацию, где вам требуется перекодировать?</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Thu, 02 Jul 2015 01:13:31 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94858#p94858</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94856#p94856</link>
			<description><![CDATA[<p>Не пойму как использовать. Подскажешь? А то сейчас приходится через временный файл кодировать.<br /></p><div class="codebox"><pre><code>str := &quot;Ä&quot;
MsgBox, % Utf2Ansi(str)

Utf2Ansi(str)
{
   FileOpen(&quot;utf8&quot;, &quot;w&quot;, &quot;CP0&quot;).Write(str)
   FileRead, ansi, utf8
   FileDelete, utf8
   Return, ansi
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Thu, 02 Jul 2015 00:56:57 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94856#p94856</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94664#p94664</link>
			<description><![CDATA[<p>Сейчас этот способ уже не актуален, для перекодировки можно использовать StrPut/StrGet.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 21 Jun 2015 09:53:45 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94664#p94664</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=94663#p94663</link>
			<description><![CDATA[<p>А как сделать с помощью этого кода конвертацию UTF-8 символов в ANSI?<br />Так не оплучается:<br /></p><div class="codebox"><pre><code>msgbox % Ansi := Utf8ToAnsi(&quot;Ä&quot;)  ; Преобразуем в Ansi.


; ---- Функция преобразования ----

Utf8ToAnsi(ByRef Utf8String, CodePage = 1251)
{
    If (NumGet(Utf8String) &amp; 0xFFFFFF) = 0xBFBBEF
        BOM = 3
    Else
        BOM = 0

    UniSize := DllCall(&quot;MultiByteToWideChar&quot;, &quot;UInt&quot;, 65001, &quot;UInt&quot;, 0
                                            , &quot;UInt&quot;, &amp;Utf8String + BOM, &quot;Int&quot;, -1
                                            , &quot;Int&quot;, 0, &quot;Int&quot;, 0)
    VarSetCapacity(UniBuf, UniSize * 2)
    DllCall(&quot;MultiByteToWideChar&quot;, &quot;UInt&quot;, 65001, &quot;UInt&quot;, 0
                                 , &quot;UInt&quot;, &amp;Utf8String + BOM, &quot;Int&quot;, -1
                                 , &quot;UInt&quot;, &amp;UniBuf, &quot;Int&quot;, UniSize)

    AnsiSize := DllCall(&quot;WideCharToMultiByte&quot;, &quot;UInt&quot;, CodePage, &quot;UInt&quot;, 0
                                             , &quot;UInt&quot;, &amp;UniBuf, &quot;Int&quot;, -1
                                             , &quot;Int&quot;, 0, &quot;Int&quot;, 0
                                             , &quot;Int&quot;, 0, &quot;Int&quot;, 0)
    VarSetCapacity(AnsiString, AnsiSize)
    DllCall(&quot;WideCharToMultiByte&quot;, &quot;UInt&quot;, CodePage, &quot;UInt&quot;, 0
                                 , &quot;UInt&quot;, &amp;UniBuf, &quot;Int&quot;, -1
                                 , &quot;Str&quot;, AnsiString, &quot;Int&quot;, AnsiSize
                                 , &quot;Int&quot;, 0, &quot;Int&quot;, 0)
    Return AnsiString
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 21 Jun 2015 09:35:09 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=94663#p94663</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=39803#p39803</link>
			<description><![CDATA[<p>Спасибо, понял.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 01 Oct 2010 17:57:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=39803#p39803</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Как перекодировать файл из UTF8 в ANSI]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=39802#p39802</link>
			<description><![CDATA[<p>Вообще-то, смотря какая кодировка. Говорят, дальневосточные ANSI многобайтные и там соотношение размеров сложнее. Поэтому и требуется такой предварительный вызов функции, чтобы узнать реальный размер выходного буфера. На случай, если вдруг такая кодировка.</p><p>Завершающий нуль в возвращённом размере будет учтён, если передана -1 в качестве размера входной строки. Это подразумевает, что строка нуль-терминирована и ноль тоже нужен. Если указать не -1, а конкретное количество символов/байтов (возможно, не всю строку), то возвращённый размер выходного буфера расчитан строго под эти символы и соответственно нуль в конец при конвертации не будет добавлен.</p>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Fri, 01 Oct 2010 17:54:14 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=39802#p39802</guid>
		</item>
	</channel>
</rss>
