<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: Нахождение длины строки]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7949&amp;type=atom" />
	<updated>2013-04-16T15:30:52Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=7949</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71463#p71463" />
			<content type="html"><![CDATA[<p>а так можно ?</p><div class="codebox"><pre><code>call :len &quot;строка&quot;                                 &amp;:: &quot;len&quot; - Переменная куда вернуть значение
 echo Длина строки: %len%</code></pre></div>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2013-04-16T15:30:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71463#p71463</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71249#p71249" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>XGuest пишет:</cite><blockquote><p>Доброго времени суток</p><p>Быстрей не видел</p></blockquote></div><p>К сожалению, тест показывает, что это самые долгие варианты функции. (1-й вариант более 24000 тиков, второй порядка 10000 тиков.)</p><p>Быстрее функции бинарного поиска, выложенного мной ранее, вариантов нету.</p>]]></content>
			<author>
				<name><![CDATA[urahangka]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29756</uri>
			</author>
			<updated>2013-04-10T08:13:12Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71249#p71249</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71180#p71180" />
			<content type="html"><![CDATA[<p>Доброго времени суток</p><p>Быстрей не видел</p><div class="codebox"><pre><code>@echo off
 call :len var &quot;строка&quot;                                 &amp;:: &quot;var&quot; - Переменная куда вернуть значение
 echo Длина строки: %var%                      
goto :eof

:len
 set len=%~2
 if not &quot;%len%&quot;==&quot;&quot; set /a %1+=1 &amp; call :len %1 &quot;%len:~1%&quot;
goto :eof</code></pre></div><br /><div class="codebox"><pre><code>@echo off
set VAR=Очень длинная строка
set BAK=%TMP%\%RANDOM%
&gt;%BAK% echo.%VAR%
for %%I in (%BAK%) do set /a len=%%~zI-2
echo Длина строки: %len%
goto :eof
</code></pre></div><br /><p>С наилучшими пожеланиями<br />XGuest</p>]]></content>
			<author>
				<name><![CDATA[XGuest]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27830</uri>
			</author>
			<updated>2013-04-07T19:37:36Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71180#p71180</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71056#p71056" />
			<content type="html"><![CDATA[<p>Скорость хорошая, практически идентичная скрипту, выложенному мной ранее(тест выдает порядка 370 тиков). Но мне не нравится двойная процедура, юзабилити не очень. Хотя, конечно, можно переделать...</p>]]></content>
			<author>
				<name><![CDATA[urahangka]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29756</uri>
			</author>
			<updated>2013-04-03T09:38:27Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71056#p71056</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71051#p71051" />
			<content type="html"><![CDATA[<p>за скорость не знаю<br /></p><div class="codebox"><pre><code>
@echo off &amp; call :%~1 &quot;%~2&quot; 2&gt; nul

set me=%~0
echo %time%
for /l %%x in (1,1,100) do call :len &quot;sdfsdf&quot;
echo %ERRORLEVEL%
echo %time%
exit

:len (str) {
    if &quot;%~1&quot;==&quot;&quot; exit /b 0 else cmd /c &quot;&quot;%me%&quot; length &quot;%~1&quot;&quot;
    exit /b %ERRORLEVEL%
}

:length (str) {
    set &quot;str=%~1&quot;
     setlocal ENABLEDELAYEDEXPANSION
    for /l %%x in (0,1,99999999999999999999) do (
        call set x=!x!%%str:~%%~x,1%%
        if &quot;!x!&quot;==&quot;!str!&quot; set /a x=%%~x+1 &amp; exit !x!
    )
    exit 0
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2013-04-03T07:27:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71051#p71051</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71002#p71002" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Rumata пишет:</cite><blockquote><p><strong>urahangka</strong>, ограничение в 4К вызвано чем - ограничением на длину строки в командной строке?</p></blockquote></div><p>Если память не отшибло, то стандартное ограничение строки - 1023. Насколько я понимаю данный скрипт по тестам, он подсчитывает длину строки вплоть до 8189 символов, если строка длиннее - все равно показывает длину 8189 символов.</p>]]></content>
			<author>
				<name><![CDATA[urahangka]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29756</uri>
			</author>
			<updated>2013-04-02T08:45:19Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71002#p71002</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71001#p71001" />
			<content type="html"><![CDATA[<p><strong>urahangka</strong>, ограничение в 4К вызвано чем - ограничением на длину строки в командной строке?</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2013-04-02T08:26:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71001#p71001</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=71000#p71000" />
			<content type="html"><![CDATA[<p>Кстати, нарыл где-то в недрах интернета функцию скрипта бинарного подсчета длины строки:</p><div class="codebox"><pre><code>
@echo off
set str=super-puper-stroka, izmeryaem dliny.
call :strlen4 str dlina
echo stroka=%str%
echo length=%dlina%
pause
exit /b

:strlen4  StrVar  RtnVar  --  be sure to check if the returned errorlevel is 0
(   setlocal enabledelayedexpansion &amp; set /a &quot;}=0&quot;
    if &quot;%~1&quot; neq &quot;&quot; if defined %~1 (
        for %%# in (4096 2048 1024 512 256 128 64 32 16) do (
            if &quot;!%~1:~%%#,1!&quot; neq &quot;&quot; set &quot;%~1=!%~1:~%%#!&quot; &amp; set /a &quot;}+=%%#&quot;
        )
        set &quot;%~1=!%~1!0FEDCBA9876543211&quot; &amp; set /a &quot;}+=0x!%~1:~32,1!!%~1:~16,1!&quot;
    )
)
endlocal &amp; set /a &quot;%~2=%}%&quot; &amp; exit /b
</code></pre></div><p>З.Ы. Очень шустрый! Быстрее выложенного мной ранее где-то в 3 раза.</p><p>Лениво делать скриншоты, так что просто выложу результаты тестирования:<br />Исходные данные:<br />&quot;деревянный&quot; комп на winXP SP3 (Core 2 Duo&nbsp; 2Гц, 2 Гб оперы)<br />строка - длина 54 символа<br />цикл - 1000 раз<br />тики (сотые доли секунды) - перед циклом и после цикла. Результат - разница между тиками.</p><p>Вариант через временный файл:&nbsp; &nbsp; &nbsp;9652 тика<br />Вариант, выложенный мной ранее: 1156 тика<br />Этот Вариант:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;355 тиков.</p>]]></content>
			<author>
				<name><![CDATA[urahangka]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29756</uri>
			</author>
			<updated>2013-04-02T07:45:51Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=71000#p71000</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70999#p70999" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p><strong>urahangka</strong>, приведите пример использования. У меня не выходит.</p></blockquote></div><div class="codebox"><pre><code>
@echo off
set str=super-puper-stroka, izmeryaem dliny.
call :strLen str dlina
echo stroka=%str%
echo length=%dlina%
pause
exit /b

:strLen stroka length
(   SETLOCAL ENABLEDELAYEDEXPANSION
    set &quot;str=A!%~1!&quot;
    set &quot;len=0&quot;
    for /L %%A in (12,-1,0) do (
        set /a &quot;len|=1&lt;&lt;%%A&quot;
        for %%B in (!len!) do if &quot;!str:~%%B,1!&quot;==&quot;&quot; set /a &quot;len&amp;=~1&lt;&lt;%%A&quot;
    )
)
( ENDLOCAL &amp; REM RETURN VALUES
    IF &quot;%~2&quot; NEQ &quot;&quot; SET /a %~2=%len%
)
EXIT /b

</code></pre></div>]]></content>
			<author>
				<name><![CDATA[urahangka]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=29756</uri>
			</author>
			<updated>2013-04-02T06:51:42Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70999#p70999</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70992#p70992" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><p>Вам еще учиться (без балды)</p></blockquote></div><p>Очень интересное высказывание на критику неправильного кода. Никто не совершенен. А дополнительные знания никому еще были лишними.</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2013-04-01T20:54:21Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70992#p70992</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70991#p70991" />
			<content type="html"><![CDATA[<p>Вам еще учиться (без балды)</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2013-04-01T20:13:39Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70991#p70991</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70990#p70990" />
			<content type="html"><![CDATA[<p>Хорошо. Проверил. </p><p>Вот слегка модифицированный код. В чем его смысл?<br /></p><div class="codebox"><pre><code>
echo off
call :len &quot;one&quot;
:return
call echo %len%
exit /b

:len (str) {
    set out=%~0
    set out=%out:~1%
    set &quot;str=%~1&quot;
    setlocal ENABLEDELAYEDEXPANSION
    for /l %%x in (0,1,9) do (
        call set t=!t!%%str:~%%~x,1%%
        if !t!==!str! set %out%=%%x &amp; call :return
    )
    exit /b
}
</code></pre></div><p>Вот результат его работы:<br /></p><div class="codebox"><pre><code>
U:\tmp&gt;echo off
2
3
4
5
6
7
8
9
ECHO is off.
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2013-04-01T20:04:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70990#p70990</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70989#p70989" />
			<content type="html"><![CDATA[<p>попробуйте</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2013-04-01T19:55:42Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70989#p70989</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70988#p70988" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><div class="codebox"><pre><code>
echo off
call :len &quot;dfljgkdflgljkgsdfg&quot;
:return
call echo %len%
exit

:len (str) {
...
call :return
...
    exit /b
}
</code></pre></div></blockquote></div><p>очень странный способ выхода из подпрограммы. А если понадобятся два вызова? Как выполнить выход в таком случае? <br /></p><div class="codebox"><pre><code>
call :len &quot;one&quot;
call echo %len%
call :len &quot;two&quot;
call echo %len%
</code></pre></div><p>Правильный код: вместо <strong>call :return</strong> написать <strong>goto :EOF</strong> или <strong>exit /b</strong></p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2013-04-01T19:48:07Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70988#p70988</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=70987#p70987" />
			<content type="html"><![CDATA[<p>скорость не знаю<br /></p><div class="codebox"><pre><code>
echo off
call :len &quot;dfljgkdflgljkgsdfg&quot;
:return
call echo %len%
exit

:len (str) {
    set out=%~0
    set out=%out:~1%
    set &quot;str=%~1&quot;
    setlocal ENABLEDELAYEDEXPANSION
    for /l %%x in (0,1,99999999999999999999) do (
        call set t=!t!%%str:~%%~x,1%%
        if !t!==!str! set %out%=%%x &amp; call :return
    )
    exit /b
}
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2013-04-01T18:33:27Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=70987#p70987</id>
		</entry>
</feed>
