<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Перекодировка содержимого переменной]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=12388</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=12388&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Перекодировка содержимого переменной».]]></description>
		<lastBuildDate>Sat, 17 Nov 2018 20:17:55 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=129893#p129893</link>
			<description><![CDATA[<p>А как конвертировать содержимое переменной из файла, который может быть закодирован в ANSI, UTF-8 или UTF-16? Можно ли универсально читать такие файлы и приводить их содержимое в UTF-8? Пробовал на следующих примерах, но тут к каждой кодировке нужны свои подходы и она должна быть заранее известна —<br /></p><div class="codebox"><pre><code>
text_file = %A_ScriptDir%\win.html

FileRead, text, %text_file%
;FileRead, text, *P65001 %text_file%  ;прочитать UTF-8 файл

text := ConvertToHtml(text)
msgbox % text

text := Decoding(text, &quot;UTF-8&quot;)
msgbox % text

text := ComUnHTML(text)
msgbox % text


Decoding(text, from, to = &quot;CP0&quot;)  {
   VarSetCapacity(var, StrPut(text, to)*((to = &quot;utf-16&quot; || to = &quot;cp1200&quot;) ? 2 : 1), 0)
   StrPut(text, &amp;var, to)
   Return StrGet(&amp;var, from)
}

ComUnHTML(html) {
	oHTML := ComObjCreate(&quot;HtmlFile&quot;)
	oHTML.write(html)
	return oHTML.documentElement.outerhtml
}

ConvertToHtml(str2htm)  {
   Loop, parse, str2htm
   {
      if AnsiTestChar(A_LoopField)
         htmlStr .= A_LoopField
      else  {
         Transform, out, HTML, % A_LoopField, 2
         htmlStr .= out
      }
   }
   Return htmlStr
}

AnsiTestChar(char)  {
   VarSetCapacity(buff, 1, 0)
   StrPut(char, &amp;buff, &quot;cp0&quot;)
   Return StrGet(&amp;buff, &quot;cp0&quot;) == char
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Sat, 17 Nov 2018 20:17:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=129893#p129893</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111927#p111927</link>
			<description><![CDATA[<p>Спасибо.</p>]]></description>
			<author><![CDATA[null@example.com (sanny0112)]]></author>
			<pubDate>Sun, 05 Feb 2017 12:40:11 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111927#p111927</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111926#p111926</link>
			<description><![CDATA[<p>Попробуйте в таком виде:<br /></p><div class="codebox"><pre><code>str := &quot;РџРµСЂРµРґР°РЅРЅС‹Рµ РІР°РјРё РїР°СЂР°РјРµС‚СЂС‹ РЅРµРІРµСЂРЅС‹&quot;
MsgBox, % Decoding(str, &quot;UTF-8&quot;)

Decoding(text, from, to = &quot;CP0&quot;)  {
   VarSetCapacity(var, StrPut(text, to)*((to = &quot;utf-16&quot; || to = &quot;cp1200&quot;) ? 2 : 1), 0)
   StrPut(text, &amp;var, to)
   Return StrGet(&amp;var, from)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 05 Feb 2017 12:20:35 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111926#p111926</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111925#p111925</link>
			<description><![CDATA[<p>У меня такого не происходит:</p><div class="codebox"><pre><code>str := &quot;РЁРёСЂРѕРєР°СЏ СЌР»РµРєС‚СЂРёС„РёРєР°С†РёСЏ СЋР¶РЅС‹С… РіСѓР±РµСЂРЅРёР№ РґР°СЃС‚ РјРѕС‰РЅС‹Р№ С‚РѕР»С‡РѕРє РїРѕРґСЉС‘РјСѓ СЃРµР»СЊСЃРєРѕРіРѕ С…РѕР·СЏР№СЃС‚РІР°.&quot;
VarSetCapacity(var, StrPut(str, &quot;CP0&quot;), 0)
StrPut(str, &amp;var, &quot;CP0&quot;)
MsgBox, % StrGet(&amp;var, &quot;UTF-8&quot;)

str := &quot;РџРµСЂРµРґР°РЅРЅС‹Рµ РІР°РјРё РїР°СЂР°РјРµС‚СЂС‹ РЅРµРІРµСЂРЅС‹&quot;
VarSetCapacity(var, StrPut(str, &quot;CP0&quot;), 0)
StrPut(str, &amp;var, &quot;CP0&quot;)
MsgBox, % StrGet(&amp;var, &quot;UTF-8&quot;)</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 05 Feb 2017 12:18:41 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111925#p111925</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111922#p111922</link>
			<description><![CDATA[<div class="quotebox"><cite>teadrinker пишет:</cite><blockquote><div class="codebox"><pre><code>str := &quot;РџРµСЂРµРґР°РЅРЅС‹Рµ РІР°РјРё РїР°СЂР°РјРµС‚СЂС‹ РЅРµРІРµСЂРЅС‹&quot;
VarSetCapacity(var, StrPut(str, &quot;CP0&quot;), 0)
StrPut(str, &amp;var, &quot;CP0&quot;)
MsgBox, % StrGet(&amp;var, &quot;UTF-8&quot;)</code></pre></div></blockquote></div><p>Нашел один баг. При первом использовании этот метод работает, но при последующих выдает знаки вопроса. Как это исправить?</p>]]></description>
			<author><![CDATA[null@example.com (sanny0112)]]></author>
			<pubDate>Sun, 05 Feb 2017 12:09:16 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111922#p111922</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111743#p111743</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, не нашел такого функционала.</p>]]></description>
			<author><![CDATA[null@example.com (sanny0112)]]></author>
			<pubDate>Wed, 01 Feb 2017 08:11:49 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111743#p111743</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111742#p111742</link>
			<description><![CDATA[<p>А там разве нельзя кодировку указать?</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Wed, 01 Feb 2017 07:35:17 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111742#p111742</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111741#p111741</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, если бы текст брался из файла, я бы так и сделал. Но я беру его напрямую с сайта, при помощи httpQuery.</p>]]></description>
			<author><![CDATA[null@example.com (sanny0112)]]></author>
			<pubDate>Wed, 01 Feb 2017 07:12:51 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111741#p111741</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111709#p111709</link>
			<description><![CDATA[<p>Но проще было бы файл, из которого считывается этот текст, сохранить в кодировке UTF-8 с помощью блокнота, и таких проблем не будет.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 31 Jan 2017 16:37:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111709#p111709</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111708#p111708</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, спасибо, тему можно закрывать.</p>]]></description>
			<author><![CDATA[null@example.com (sanny0112)]]></author>
			<pubDate>Tue, 31 Jan 2017 16:34:43 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111708#p111708</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111707#p111707</link>
			<description><![CDATA[<div class="codebox"><pre><code>str := &quot;РџРµСЂРµРґР°РЅРЅС‹Рµ РІР°РјРё РїР°СЂР°РјРµС‚СЂС‹ РЅРµРІРµСЂРЅС‹&quot;
VarSetCapacity(var, StrPut(str, &quot;CP0&quot;), 0)
StrPut(str, &amp;var, &quot;CP0&quot;)
MsgBox, % StrGet(&amp;var, &quot;UTF-8&quot;)</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 31 Jan 2017 16:25:35 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111707#p111707</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111706#p111706</link>
			<description><![CDATA[<p>Никак вроде.</p>]]></description>
			<author><![CDATA[null@example.com (slavafedora)]]></author>
			<pubDate>Tue, 31 Jan 2017 16:20:18 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111706#p111706</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Перекодировка содержимого переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=111704#p111704</link>
			<description><![CDATA[<p>Приветствую. Переменная содержит строку следующего характера:<br /></p><div class="codebox"><pre><code> РџРµСЂРµРґР°РЅРЅС‹Рµ РІР°РјРё РїР°СЂР°РјРµС‚СЂС‹ РЅРµРІРµСЂРЅС‹</code></pre></div><p>Как посредством AHK преобразовать данную строку в нормальный текст?</p>]]></description>
			<author><![CDATA[null@example.com (sanny0112)]]></author>
			<pubDate>Tue, 31 Jan 2017 16:18:05 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=111704#p111704</guid>
		</item>
	</channel>
</rss>
