<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=16881&amp;type=atom" />
	<updated>2022-01-13T15:25:51Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=16881</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151637#p151637" />
			<content type="html"><![CDATA[<p><strong>Alectric</strong>, просьба, если видите, что было сделано замечание по оформлению, а исправления пока не сделаны, новые посты в теме создавать не нужно.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-01-13T15:25:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151637#p151637</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151635#p151635" />
			<content type="html"><![CDATA[<p>С переключателем.<br /></p><div class="codebox"><pre><code>global encoding
gui,1:font,s8,Tahoma
Gui,1:Add,Radio,Checked vChoice w100 gsubm,utf-16
Gui,1:Add,Radio,xp y+10 w100 gsubm,utf-8
gui,1:add,text,,Вставь сюда текст:
gui,1:add,edit,vintext w400 h100 gConvert,
gui,1:add,text,,Вставь сюда HEX:
gui,1:add,edit,vouttext w400 h100 gConvert2,
gui,show
return

Convert:
gui,1:submit,nohide
size:=STRToDATA(intext,tmp1,encoding)
HEXText:=DATAtoHEX(&amp;tmp1,0,size)
GuiControl,,outtext,%HEXText%
return

Convert2:
gui,1:submit,nohide
size:=HEXstrToDATA(outtext,tmp1,0)
StrText:=DATAtoSTR(&amp;tmp1,encoding,size)
GuiControl,,intext,%StrText%
return

subm:
gui,1:submit,nohide
encoding:=Choice-1
gosub,Convert
return

STRToDATA(str,byref var,enc)
{
    size:=enc?strlen(str):strlen(str)*2
    varsetcapacity(var,size)
    StrPut(str,&amp;var,enc?&quot;utf-8&quot;:&quot;utf-16&quot;)
    return size
}

DATAtoHEX(var,st,size,sw=0)
{
    loop,% size
    {
        hex.=format(&quot;{:02X},&quot;,numget(var+0,(sw?(size-a_index):(st+a_index-1)),&quot;uchar&quot;))
        if (!mod(a_index,23) and a_index!=size)
            hex.=&quot;\`n&quot;
    }
    stringtrimright,hex,hex,1
    return hex
}

HEXstrToDATA(str,byref var,swap=0)
{
    stringreplace,str,str,%a_space%,,all
    stringreplace,str,str,`\,,all
    stringreplace,str,str,`n,,all
    if RegExMatch(str,&quot;00&quot;)
      encoding:=0
    stringreplace,str,str,`,,,all
    size:=ceil(strlen(str)/2)
    varsetcapacity(var,size+2)
    loop,% size
    {
        stringright,tmp2,str,2
        if !swap
            NumPut(&quot;0x&quot;tmp2,var,size-a_index,&quot;Uchar&quot;)
        else
            NumPut(&quot;0x&quot;tmp2,var,a_index-1,&quot;Uchar&quot;)
        StringTrimRight,str,str,2

    }
    return size
}

DATAtoSTR(var,enc,size,sw=0)
{
  return StrGet(var,enc?size:size/2,enc?&quot;utf-8&quot;:&quot;utf-16&quot;)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2022-01-13T14:52:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151635#p151635</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151634#p151634" />
			<content type="html"><![CDATA[<p><strong>BlackCat</strong>, пожалуйста, не пишите каждое предложение с новой строки, у нас тут не вотсап. Ставьте точку в конце каждого предложения. Много точек ставить не нужно, это выглядит глупо. Исправьте пожалуйста свои посты.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-01-13T14:36:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151634#p151634</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151630#p151630" />
			<content type="html"><![CDATA[<p><strong>Alectric</strong> возможно, но это лишние &quot;переключалки&quot; в gui.<br />Хотел сделать максимально простой интерфейс без лишних заморочек.<br />Возможно придется делать лишнюю фигню в gui, печалька<br />Или оставить все, как есть - код дает сбой только на одной фигне, которая может и не встретиться вовсе.</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2022-01-13T13:38:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151630#p151630</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151629#p151629" />
			<content type="html"><![CDATA[<p>Нужно делать переключатель ANSI - Unicode, наверно.<br /></p><div class="quotebox"><cite>Справка пишет:</cite><blockquote><p>Gui, Add, Radio, vMyRadioGroup, Wait for all items to be in stock before shipping.</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2022-01-13T13:35:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151629#p151629</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151628#p151628" />
			<content type="html"><![CDATA[<p><strong>Alectric</strong> ну да, я тестил на кириллице.<br />Вообще это проблемка - кириллица часто встречается в реестре.</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2022-01-13T13:33:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151628#p151628</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151627#p151627" />
			<content type="html"><![CDATA[<p>Еще раз поправил. HEX строку в нижний вставляй, в верхнем текст изменится. Только мой вариант с русским текстом не дружит.</p>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2022-01-13T13:29:57Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151627#p151627</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151626#p151626" />
			<content type="html"><![CDATA[<p><strong>Alectric</strong> нифика оно не мурлычит.<br />К тому-же 4 окна неудобно.<br />Если бы как-то научить распознавать код текс/хекс.<br />В моем коде делает эта фигня:<br /></p><div class="codebox"><pre><code>Convert:
	GuiControlGet, Source
	If RegExMatch(Source, &quot;^\h*(\d\d,|\d\w,)+&quot;){
		GetTxt()
		}
		Else {
			GetHex()
			}</code></pre></div><p>Но на двух цифрах с запятой дает сбой.<br />Либо шаблон нужно сделать крутой, либо что-то придумать другое - без RegEx</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2022-01-13T13:24:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151626#p151626</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151625#p151625" />
			<content type="html"><![CDATA[<p>Поправил, попробуй.</p>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2022-01-13T13:18:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151625#p151625</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151624#p151624" />
			<content type="html"><![CDATA[<p><strong>Alectric</strong> а в обратку-то оно не переводит <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />В смысле, если конвертированный результат строки в hex опять вставить для перевода, выход опять в hex.<br />Мой код переводит туда-сюда, если до бесконечности вставлять и конвертировать результат.<br />Проблема только в том, что он распознает не как строку, а как hex, если строка начинается с двух цифр и запятой (38, попугаев - пример).</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2022-01-13T13:09:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151624#p151624</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151623#p151623" />
			<content type="html"><![CDATA[<p>Дело было вечером, делать было нечего.<br /></p><div class="codebox"><pre><code>gui,1:font,s8,Tahoma
gui,1:add,edit,vintext w400 h100 gConvert,
gui,1:add,edit,vouttext w400 h100 gConvert2,
gui,show
return

Convert:
gui,1:submit,nohide
size:=STRToDATA(intext,tmp1,0)
HEXText:=DATAtoHEX(&amp;tmp1,0,size)
GuiControl,,outtext,%HEXText%
return

Convert2:
gui,1:submit,nohide
size:=HEXstrToDATA(outtext,tmp1,0)
StrText:=DATAtoSTR(&amp;tmp1,0,size)
GuiControl,,intext,%StrText%
return


STRToDATA(str,byref var,swap=0)
{
  size:=strlen(str)
  varsetcapacity(var,size+2)
  loop,parse,str
  {
    if !swap
      NumPut(asc(a_loopfield),var,a_index-1,&quot;Uchar&quot;)
    else
      NumPut(asc(a_loopfield),var,size-a_index,&quot;Uchar&quot;)
  }
  return size
}

DATAtoHEX(var,st,size,sw=0)
{
  loop,% size
  {
    hex.=format(&quot;{:02X},&quot;,numget(var+0,(sw?(size-a_index):(st+a_index-1)),&quot;uchar&quot;))
    if (!mod(a_index,23) and a_index!=size)
      hex.=&quot;\`n&quot;
  }
  stringtrimright,hex,hex,1
  return hex
}







HEXstrToDATA(str,byref var,swap=0)
{
  stringreplace,str,str,%a_space%,,all
  stringreplace,str,str,`\,,all
  stringreplace,str,str,`n,,all
  stringreplace,str,str,`,,,all
  size:=ceil(strlen(str)/2)
  varsetcapacity(var,size+2)
  loop,% size
  {
    stringright,tmp2,str,2
    if !swap
      NumPut(&quot;0x&quot;tmp2,var,size-a_index,&quot;Uchar&quot;)
    else
      NumPut(&quot;0x&quot;tmp2,var,a_index-1,&quot;Uchar&quot;)
    StringTrimRight,str,str,2

 }
  return size
}

DATAtoSTR(var,st,size,sw=0)
{
  loop,% size
    str.=chr(numget(var+0,(sw?(size-a_index):(st+a_index-1)),&quot;uchar&quot;))
  return str
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2022-01-13T12:59:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151623#p151623</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151619#p151619" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong> постараюсь разобраться, ежели че - к вам приду за помощью <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Благодарю!</p>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2022-01-13T10:01:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151619#p151619</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151618#p151618" />
			<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>2022-01-13T09:59:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151618#p151618</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151617#p151617" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong> благодарю за ответ и подсказку!<br />Хотелось бы уточнить - эти функции конвертируют в формат реестра?<br />Нужно получать результат такого вида:<br /></p><div class="codebox"><pre><code>22,00,25,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,6c,\
  00,65,00,73,00,25,00,5c,00,4e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2b,00,\
  2b,00,5c,00,6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2b,00,2b,00,2e,00,65,\
  00,78,00,65,00,22,00,20,00,22,00,25,00,31,00,22,00,00,00</code></pre></div>]]></content>
			<author>
				<name><![CDATA[BlackCat]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=41382</uri>
			</author>
			<updated>2022-01-13T09:56:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151617#p151617</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: RegHex Converter - ввод данных с двумя цифрами и запятой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=151613#p151613" />
			<content type="html"><![CDATA[<p>Для конвертации в hex и обратно не нужно использовать регулярки, есть winapi функции CryptBinaryToString и CryptStringToBinary, ищите примеры использования.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-01-13T09:45:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=151613#p151613</id>
		</entry>
</feed>
