<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Object.HasKey() => Разобрался]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=12218</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=12218&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Object.HasKey() => Разобрался».]]></description>
		<lastBuildDate>Mon, 12 Dec 2016 21:26:49 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[AHK: Object.HasKey() => Разобрался]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=109820#p109820</link>
			<description><![CDATA[<p>Добра всем читающим!<br />Поделитесь пожалуйста мудростью. Пишу в текстовом файле &quot;data.txt&quot; строчку наобум:<br /></p><div class="codebox"><pre><code>
N78NU6BNKJ,LJN&amp;Y,7JBY6,097hbKU,NNNNNNNY
</code></pre></div><p>Сохраняю в UTF-8. Затем хочу получить первый набор символов до запятой в параметр &#039;key&#039; для ассоциированного массива, а остальные в параметр для этого ключа, который будет массивом:<br /></p><div class="codebox"><pre><code>
collectionData:=GetCollectionData(&quot;data.txt&quot;)
a:=&quot;&quot;
for w, e in collectionData
{
	a:=% &quot;key = &quot; w &quot;`n`nValues:`n&quot;
	while (A_Index&lt;=e.Length())
		a:=% a e[A_Index] &quot;`n&quot;
}
MsgBox,, Title, % a &quot;`n`n HasKey(N78NU6BNKJ) = &quot; collectionData.HasKey(&quot;N78NU6BNKJ&quot;)
GetCollectionData(readFile) {
	collection:={},itemsArr:=[]
	file:=FileOpen(readFile, &quot;r&quot;, &quot;UTF-8&quot;)
	file.Seek(0)
	strItems:=StrSplit(file.ReadLine(),&quot;,&quot;,&quot;`r`n&quot;)
	if (strItems.Length()&lt;2)
		return
	file.Seek(0)
	while (file.Tell()&lt;file.Length) {
		itemsArr:=StrSplit(file.ReadLine(),&quot;,&quot;,&quot;`r`n&quot;)
		i:=2,collection[itemsArr[1]]:=[],totalDatacount++
		while (i&lt;=itemsArr.Length()) {
			collection[itemsArr[1]].Push(itemsArr[i])
			i++
		}
	}
	file.Close()
	return collection
}
</code></pre></div><p>МесседжБокс выводит результат, в котором в его понимании нет такого ключа. Переделал в двумерный массив:<br /></p><div class="codebox"><pre><code>
collectionData:=GetData(&quot;data.txt&quot;)
totalStr:=&quot;&quot;
i:=2,j:=1
while (j&lt;=collectionData.Length()) {
	while (i&lt;=collectionData[j].Length()) {
		totalStr:=% totalStr &quot;Key=&quot; collectionData[j][1] &quot;; Val=&quot; collectionData[j][i] &quot;`n&quot;
		i++
	}
	j++
}
MsgBox,, Title, % totalStr
if (collectionData[1][1] == &quot;N78NU6BNKJ&quot;)
	MsgBox,, Title, TRUE
else
	MsgBox,, Title, % &quot;&#039;&quot; collectionData[1][1] &quot;&#039;`n&#039;N78NU6BNKJ&#039;`n&quot; CheckString(collectionData[1][1], &quot;N78NU6BNKJ&quot;) &quot;`n`nStrLen(arr) =&gt; &quot; StrLen(collectionData[1][1]) &quot; StrLen(str) =&gt; &quot; StrLen(&quot;N78NU6BNKJ&quot;)

GetData(readFile) {
	dataArr:=[]
	file:=FileOpen(readFile, &quot;r&quot;, &quot;UTF-8&quot;)
	file.Seek(0)
	strItems:=StrSplit(file.ReadLine(),&quot;,&quot;,&quot;`r`n&quot;)
	if (strItems.Length()&lt;2)
		return
	file.Seek(0)
	while (file.Tell()&lt;file.Length) {
		dataArr.Push(StrSplit(file.ReadLine(),&quot;,&quot;,&quot;`r`n&quot;))
	}
	file.Close()
	return dataArr
}
CheckString(mainStr, srchStr) {
	if mainStr contains %srchStr%
		return true
	return false
}
</code></pre></div><p>И так же, данные из ячейки [1][1] не соответствуют &quot;N78NU6BNKJ&quot;, в то время как проверка на содержание в этой ячейки строки &quot;N78NU6BNKJ&quot; возвращают единицу. =/<br />Не понимаю, как так. Где у этого велосипеда поломка?</p><p>Обновлено:<br />В последнем примере, StrLen() - показывает разное количество символов, 11 и 10 соответственно. В то время как текст заключённый в одинарные кавычки идентичен.</p><p>Обновлено 2:<br />Как оказалось, такой эффект вызывает перемещение указателя в начало файла:<br /></p><div class="codebox"><pre><code>
file.Seek(0)
</code></pre></div><p>Переделал проверку на размер файла, убрав это перемещение в начало и заработало. Вместо:<br /></p><div class="codebox"><pre><code>
	file.Seek(0)
	strItems:=StrSplit(file.ReadLine(),&quot;,&quot;,&quot;`r`n&quot;)
	if (strItems.Length()&lt;2)
		return
	file.Seek(0)
</code></pre></div><p>Это:<br /></p><div class="codebox"><pre><code>
	if (file.Length&lt;2)
		return
</code></pre></div><p>Всем, кто дочитал до этого места плюс в карму! Будье внимательны и не напрягайте голову перед сном! xD</p>]]></description>
			<author><![CDATA[null@example.com (KusochekDobra)]]></author>
			<pubDate>Mon, 12 Dec 2016 21:26:49 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=109820#p109820</guid>
		</item>
	</channel>
</rss>
