<?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=14528&amp;type=atom" />
	<updated>2019-01-30T23:03:44Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14528</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131803#p131803" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>Но сначала читаю `r`n как `n.</p></blockquote></div><p>Если файл с `n, перезаписываешь с `r`n — некорректно.<br />Лучше так, без всяких фокусов:<br /></p><div class="codebox"><pre><code>countStrings := 3
text =
(
1 строка
2 строка
3 строка
4 строка
5 строка
)

Loop % countStrings {
   text := MoveStringsToEnd(text, 1, moved)
   MsgBox, Запустить: %moved%
}
MsgBox, % &quot;Новый файл:`n`n&quot; text
Return

MoveStringsToEnd(text, count, ByRef moved) {
   RegExMatch(text, &quot;sO)((?:[^`n`r]+(\R)){&quot; . count . &quot;})(.*)&quot;, match)
   Return match[1] != &quot;&quot; ? match[3] . match[2] . (moved := RegExReplace(match[1], &quot;\R$&quot;)) : text
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-30T23:03:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131803#p131803</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131802#p131802" />
			<content type="html"><![CDATA[<p>Так поймёте:<br /></p><div class="codebox"><pre><code>countStrings := 3
text =
(
1 строка
2 строка
3 строка
4 строка
5 строка
) 
newText := MoveStringsToEnd(text, countStrings, part)
Loop, Parse, part, `n
	MsgBox, % &quot;Запустить: &quot; A_LoopField
MsgBox, % &quot;Новый файл:`n`n&quot; newText
Return

MoveStringsToEnd(text, count, byref part, d := &quot;`n&quot;) {
	p := InStr(text, d, 0, 1, count)
	Return p ? SubStr(text, p+1) d (part := SubStr(text, 1, p-1)) : text
}</code></pre></div><p><strong>teadrinker</strong><br />Но сначала читаю `r`n как `n.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-30T22:42:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131802#p131802</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131801#p131801" />
			<content type="html"><![CDATA[<p>Так, спасибо вроде разобрался, но только не совсем подходит под мои задачи, нужно чтобы каждую строку по одной выдавал в MsgBox, а не все сразу. Сам файл перезаписывается как надо! Уже большое спасибо за это! Но повторюсь, тут дело в том, что каждая строка это exe по сути, и он будет запускаться с помощью Run, поэтому и нужно чтобы скрипт AHK сместил первые три строки например вниз, но в тоже время и запустил их 01.exe, 02.exe, 03.exe</p>]]></content>
			<author>
				<name><![CDATA[trezubec]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39916</uri>
			</author>
			<updated>2019-01-30T21:55:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131801#p131801</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131800#p131800" />
			<content type="html"><![CDATA[<p>А, не обратил внимания. Так переписываешь файл с `n на `r`n.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-30T21:37:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131800#p131800</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131799#p131799" />
			<content type="html"><![CDATA[<p>Думаешь FileOpen с &quot;rw`n&quot; не на все случаи?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-30T21:28:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131799#p131799</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131798#p131798" />
			<content type="html"><![CDATA[<p>А откуда ты взял, что d = &quot;`n&quot;?</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-30T21:22:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131798#p131798</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131797#p131797" />
			<content type="html"><![CDATA[<p><strong>trezubec</strong><br /></p><div class="codebox"><pre><code>
#SingleInstance Force
#NoEnv
#Persistent

FileName = %A_ScriptFullPath%
File := FileOpen(FileName, &quot;rw`n&quot;)
File.Pos := 0
FileStr := File.Read()   
File.Length := 0
MsgBox % FileStr   
newText := MoveStringsToEnd(FileStr, 10)
MsgBox % newText 
File.Write(newText)
File.Close()
Return

MoveStringsToEnd(text, count, d := &quot;`n&quot;) {
	p := InStr(text, d, 0, 1, count) 
	Return p ? SubStr(text, p+1) d SubStr(text, 1, p-1) : text
}

</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-30T21:11:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131797#p131797</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131796#p131796" />
			<content type="html"><![CDATA[<p>RegEx наверное тоже не нужен.<br /></p><div class="codebox"><pre><code>countStrings := 4
text =
(
1 строка
2 строка
3 строка
4 строка
5 строка
) 
newText := MoveStringsToEnd(text, countStrings)
MsgBox, % newText
Return

MoveStringsToEnd(text, count, d := &quot;`n&quot;) {
	p := InStr(text, d, 0, 1, count) 
	Return p ? SubStr(text, p+1) d SubStr(text, 1, p-1) : text
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-30T21:02:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131796#p131796</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131795#p131795" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />countStrings := 1 пробовал.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2019-01-30T20:57:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131795#p131795</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131794#p131794" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Прошу прощения что я баран )) Но можно ли привести на моем примере с файлом, я не совсем понял куда я должен в скрипт вписать название файла )</p>]]></content>
			<author>
				<name><![CDATA[trezubec]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39916</uri>
			</author>
			<updated>2019-01-30T20:54:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131794#p131794</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131793#p131793" />
			<content type="html"><![CDATA[<p>Для этого Loop вовсе не нужен.<br /></p><div class="codebox"><pre><code>countStrings := 3
text =
(
1 строка
2 строка
3 строка
4 строка
5 строка
)
newText := MoveStringsToEnd(text, countStrings)
MsgBox, % newText
Return

MoveStringsToEnd(text, count) {
   RegExMatch(text, &quot;O)([^`n`r]+(\R|$)??){&quot; . count . &quot;}&quot;, match)
   Return match ? RegExReplace( SubStr(text, match.Len + StrLen(match[2]) + 1), &quot;\R*$&quot;, match[2] . match[0],, 1 ) : text
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2019-01-30T20:27:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131793#p131793</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Вырезание строки из файла]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=131779#p131779" />
			<content type="html"><![CDATA[<p>Уважаемые гуру, помогите пожалуйста с кодом.<br />Он наверное безобразный, т.к. я частями его собрал с разных тем форумов.</p><p>Вот что получилось</p><div class="codebox"><pre><code>FILE = Список.txt

FileRead, out, %FILE%
loop, parse, out, `n, `r
{
	CNT_STROK:=a_index ; - запись в CNT_STROK количество строк
	If (A_LoopField != &quot;&quot;)
		Num++
}
FileReadLine, line, %FILE%, 1

Loop, read, %FILE%, tempfile.txt
{
   IfNotInString, A_LoopReadLine, %line%, FileAppend, %A_LoopReadLine%`n
}

FileMove, tempfile.txt, %FILE%, 1
}</code></pre></div><p>Список в файле это название профилей браузера, каждая из строк будет потом запускать браузер с нужным профилем, это я постараюсь сам реализовать.</p><p>К вам я за помощью по коду, если не затруднит, подскажите, как переделать код так, чтобы в цикле можно было указать количество строк для вырезания, например Loop, 3, т.е. три строки первые строки вырезаем и смещаем их в тот же файл, но в конец, и после каждого пройденного цикла, выдавал MsgBox с названием вырезанной строки..</p><p>Можно ли переделать данный код под эту задачу? Буду очень признателен за Вашу помощь!</p>]]></content>
			<author>
				<name><![CDATA[trezubec]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39916</uri>
			</author>
			<updated>2019-01-30T13:09:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=131779#p131779</id>
		</entry>
</feed>
