<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Перекодировка содержимого переменной]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=12388&amp;type=atom" />
	<updated>2018-11-17T20:17:55Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=12388</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129893#p129893" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[DD]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25263</uri>
			</author>
			<updated>2018-11-17T20:17:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129893#p129893</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111927#p111927" />
			<content type="html"><![CDATA[<p>Спасибо.</p>]]></content>
			<author>
				<name><![CDATA[sanny0112]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34083</uri>
			</author>
			<updated>2017-02-05T12:40:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111927#p111927</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111926#p111926" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-02-05T12:20:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111926#p111926</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111925#p111925" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-02-05T12:18:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111925#p111925</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111922#p111922" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[sanny0112]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34083</uri>
			</author>
			<updated>2017-02-05T12:09:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111922#p111922</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111743#p111743" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, не нашел такого функционала.</p>]]></content>
			<author>
				<name><![CDATA[sanny0112]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34083</uri>
			</author>
			<updated>2017-02-01T08:11:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111743#p111743</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111742#p111742" />
			<content type="html"><![CDATA[<p>А там разве нельзя кодировку указать?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-02-01T07:35:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111742#p111742</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111741#p111741" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, если бы текст брался из файла, я бы так и сделал. Но я беру его напрямую с сайта, при помощи httpQuery.</p>]]></content>
			<author>
				<name><![CDATA[sanny0112]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34083</uri>
			</author>
			<updated>2017-02-01T07:12:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111741#p111741</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111709#p111709" />
			<content type="html"><![CDATA[<p>Но проще было бы файл, из которого считывается этот текст, сохранить в кодировке UTF-8 с помощью блокнота, и таких проблем не будет.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-01-31T16:37:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111709#p111709</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111708#p111708" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, спасибо, тему можно закрывать.</p>]]></content>
			<author>
				<name><![CDATA[sanny0112]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34083</uri>
			</author>
			<updated>2017-01-31T16:34:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111708#p111708</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111707#p111707" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2017-01-31T16:25:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111707#p111707</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111706#p111706" />
			<content type="html"><![CDATA[<p>Никак вроде.</p>]]></content>
			<author>
				<name><![CDATA[slavafedora]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34221</uri>
			</author>
			<updated>2017-01-31T16:20:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111706#p111706</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Перекодировка содержимого переменной]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=111704#p111704" />
			<content type="html"><![CDATA[<p>Приветствую. Переменная содержит строку следующего характера:<br /></p><div class="codebox"><pre><code> РџРµСЂРµРґР°РЅРЅС‹Рµ РІР°РјРё РїР°СЂР°РјРµС‚СЂС‹ РЅРµРІРµСЂРЅС‹</code></pre></div><p>Как посредством AHK преобразовать данную строку в нормальный текст?</p>]]></content>
			<author>
				<name><![CDATA[sanny0112]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34083</uri>
			</author>
			<updated>2017-01-31T16:18:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=111704#p111704</id>
		</entry>
</feed>
