<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; CMD/BAT: Нахождение длины строки]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=7949</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7949&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «CMD/BAT: Нахождение длины строки».]]></description>
		<lastBuildDate>Tue, 16 Apr 2013 15:30:52 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71463#p71463</link>
			<description><![CDATA[<p>а так можно ?</p><div class="codebox"><pre><code>call :len &quot;строка&quot;                                 &amp;:: &quot;len&quot; - Переменная куда вернуть значение
 echo Длина строки: %len%</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Tue, 16 Apr 2013 15:30:52 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71463#p71463</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71249#p71249</link>
			<description><![CDATA[<div class="quotebox"><cite>XGuest пишет:</cite><blockquote><p>Доброго времени суток</p><p>Быстрей не видел</p></blockquote></div><p>К сожалению, тест показывает, что это самые долгие варианты функции. (1-й вариант более 24000 тиков, второй порядка 10000 тиков.)</p><p>Быстрее функции бинарного поиска, выложенного мной ранее, вариантов нету.</p>]]></description>
			<author><![CDATA[null@example.com (urahangka)]]></author>
			<pubDate>Wed, 10 Apr 2013 08:13:12 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71249#p71249</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71180#p71180</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (XGuest)]]></author>
			<pubDate>Sun, 07 Apr 2013 19:37:36 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71180#p71180</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71056#p71056</link>
			<description><![CDATA[<p>Скорость хорошая, практически идентичная скрипту, выложенному мной ранее(тест выдает порядка 370 тиков). Но мне не нравится двойная процедура, юзабилити не очень. Хотя, конечно, можно переделать...</p>]]></description>
			<author><![CDATA[null@example.com (urahangka)]]></author>
			<pubDate>Wed, 03 Apr 2013 09:38:27 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71056#p71056</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71051#p71051</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Wed, 03 Apr 2013 07:27:37 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71051#p71051</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71002#p71002</link>
			<description><![CDATA[<div class="quotebox"><cite>Rumata пишет:</cite><blockquote><p><strong>urahangka</strong>, ограничение в 4К вызвано чем - ограничением на длину строки в командной строке?</p></blockquote></div><p>Если память не отшибло, то стандартное ограничение строки - 1023. Насколько я понимаю данный скрипт по тестам, он подсчитывает длину строки вплоть до 8189 символов, если строка длиннее - все равно показывает длину 8189 символов.</p>]]></description>
			<author><![CDATA[null@example.com (urahangka)]]></author>
			<pubDate>Tue, 02 Apr 2013 08:45:19 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71002#p71002</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71001#p71001</link>
			<description><![CDATA[<p><strong>urahangka</strong>, ограничение в 4К вызвано чем - ограничением на длину строки в командной строке?</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Tue, 02 Apr 2013 08:26:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71001#p71001</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=71000#p71000</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (urahangka)]]></author>
			<pubDate>Tue, 02 Apr 2013 07:45:51 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=71000#p71000</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=70999#p70999</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (urahangka)]]></author>
			<pubDate>Tue, 02 Apr 2013 06:51:42 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=70999#p70999</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=70992#p70992</link>
			<description><![CDATA[<div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><p>Вам еще учиться (без балды)</p></blockquote></div><p>Очень интересное высказывание на критику неправильного кода. Никто не совершенен. А дополнительные знания никому еще были лишними.</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Mon, 01 Apr 2013 20:54:21 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=70992#p70992</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=70991#p70991</link>
			<description><![CDATA[<p>Вам еще учиться (без балды)</p>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Mon, 01 Apr 2013 20:13:39 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=70991#p70991</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=70990#p70990</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Mon, 01 Apr 2013 20:04:34 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=70990#p70990</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=70989#p70989</link>
			<description><![CDATA[<p>попробуйте</p>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Mon, 01 Apr 2013 19:55:42 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=70989#p70989</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=70988#p70988</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Mon, 01 Apr 2013 19:48:07 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=70988#p70988</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Нахождение длины строки]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=70987#p70987</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Mon, 01 Apr 2013 18:33:27 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=70987#p70987</guid>
		</item>
	</channel>
</rss>
