
BTW Was this known to work?
Code: Select all
if not defined %%1 (if %%? lss ' endlocal)^&(set /a %%2=0) else^
Code: Select all
if not defined %%1 ((if %%? lss ' endlocal)^&set /a %%2=0) else^
Moderator: DosItHelp
Code: Select all
if not defined %%1 (if %%? lss ' endlocal)^&(set /a %%2=0) else^
Code: Select all
if not defined %%1 ((if %%? lss ' endlocal)^&set /a %%2=0) else^
Code: Select all
(if a==a call) && (if b==a call) && ...
Code: Select all
(if ... (..)&..&(..) else ..)
Code: Select all
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLen
:: Computes the number of resulting UTF-16 code units in a string.
:: %strLen% str [len]
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out, Optional] Name of the variable that receives the measured
:: length. If omitted, the result is assigned to variable len.
:: Variable names must be passed unquoted.
:: Strings of up to 8191 characters are supported.
%== ! -> exclamation mark, # -> caret ==% FOR /F "TOKENS=1-3" %%! IN (
"! ! ^ ^^^! . ^!=^!^^^^"
) DO FOR %%H IN (FEDCBA9876543210) DO ^
set strlen=^
%==% for /f %%? in ("%%! '") do for %%. in (1 2) do if %%.==2 (^
%= =% for /f "tokens=1,2" %%1 in ("%%!$args%%! len") do^
%= =% if not defined %%1 (if %%? lss ' endlocal)^&(set /a %%2=0) else^
%= =% (if : neq :%%!%%1:~4095%%! (set $=1%%!%%1:~4096%%!)^
%= =% else set $=0%%!%%1%%!)^&^
%= =% set $Scale=^
%= =%%%!$:~256%%#,1%%!%%!$:~512%%#,1%%!%%!$:~768%%#,1%%!%%!$:~1024%%#,1%%!^
%= =%%%!$:~1280%%#,1%%!%%!$:~1536%%#,1%%!%%!$:~1792%%#,1%%!%%!$:~2048%%#,1%%!^
%= =%%%!$:~2304%%#,1%%!%%!$:~2560%%#,1%%!%%!$:~2816%%#,1%%!%%!$:~3072%%#,1%%!^
%= =%%%!$:~3328%%#,1%%!%%!$:~3584%%#,1%%!%%!$:~3840%%#,1%%!%%H^&^
%= =% for %%_ in (%%!$Scale:~15%%#,1%%!) do set $=%%!$:~%%#,1%%!^
%= =%%%!$:~0x%%_00%%!%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H^
%= =%FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
%= =%BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
%= =%7777777777777777666666666666666655555555555555554444444444444444^
%= =%3333333333333333222222222222222211111111111111110000000000000000^&^
%= =% for %%- in (%%!$:~%%#,1%%!%%_%%!$:~513%%#,1%%!%%!$:~257%%#,1%%!) do^
%= =% (if %%? lss ' endlocal)^&set /a %%2=0x%%-^
%==% ) else (if %%? gtr ' setlocal enabledelayedexpansion)^&set $args=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Code: Select all
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLenAll
:: Computes the number of bytes in a string.
:: %strLen% str len
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out] Name of the variable that receives the measured length.
:: Strings of up to 8191 characters are supported.
%== ! -> exclamation mark, # -> caret ==% @FOR /F "tokens=1-3" %%! IN (
"! ! ^ ^^^! . ^^^^") DO @^
set strLen=@^
for /f %%? in ("%%! '") do @for %%. in (1 2) do @if %%.==2 ^
for /f tokens%%#=1-2 %%1 in ("%%!$args%%! len") do^
@if not defined %%1 (if %%? lss ' endlocal)^&(set /a %%2=0) else^
for /f tokens%%#=4delims%%#=%%# %%4 in^
("x %%!%%1:~4095,1%%! x%%!%%1:~4095,1%%!x 1 0") do @set $=A%%!%%1:~0x%%4000%%!^&^
set $Scale=^
%%!$:~256%%#,1%%!%%!$:~512%%#,1%%!%%!$:~768%%#,1%%!%%!$:~1024%%#,1%%!%%!$:~1280%%#,1%%!^
%%!$:~1536%%#,1%%!%%!$:~1792%%#,1%%!%%!$:~2048%%#,1%%!%%!$:~2304%%#,1%%!%%!$:~2560%%#,1%%!^
%%!$:~2816%%#,1%%!%%!$:~3072%%#,1%%!%%!$:~3328%%#,1%%!%%!$:~3584%%#,1%%!%%!$:~3840%%#,1%%!^
FEDCBA9876543210^&^
for %%3 in (%%!$Scale:~15%%#,1%%!) do @set $=%%!$:~0x%%300%%!^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210^
FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
7777777777777777666666666666666655555555555555554444444444444444^
3333333333333333222222222222222211111111111111110000000000000000^&^
for %%$ in (%%4%%3%%!$:~512%%#,1%%!%%!$:~256%%#,1%%!) do^
@(if %%? lss ' endlocal)^&(set /A %%2=0x%%$^
) else (if %%? GTR ' setlocal enabledelayedexpansion)^&set $args=
@goto :eof
Code: Select all
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLen2v
:: Computes the number of bytes in a string.
:: %strLen% str len
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out] Name of the variable that receives the measured length.
:: Strings of up to 8191 characters are supported.
FOR /F %%! IN ("! ! ^ ^^^^^^^^^^^!") DO set i=%%!%%1:~03777,1%%!^
x%%!%%1:~03777,1%%!x&set o=%%!%%1:~0%%4777,1%%! x%%!%%1:~0%%4777,1%%!x^
%%!%%1:~0%%4377,1%%! x%%!%%1:~0%%4377,1%%!x
set F=FEDCBA9876543210&set $=0000000000000000
%== ! -> exclamation mark, # -> caret ==% @FOR /F "tokens=1-3" %%! IN (
"! ! ^ ^^^! . ^^^^") DO ^
set strLen=^
for /f %%? in ("%%! '") do for %%. in (1 2) do if %%.==2 ^
for /f tokens%%#=1-2 %%1 in ("%%!$args%%! len") do^
if not defined %%1 (if %%? lss ' endlocal)^&(set /A %%2=0) else^
for /f "tokens=7,11,15,19delims= " %%4 in (^"^
%i% %i:3=7% %i:3=13% 17 13 7 3 16 12 6 2 15 11 5 1 14 10 4 0^") do^
for /f tokens%%#=15delims%%#=%%# %%3 in (^" %o:4=7% %o:4=6% %o:4=5% %o:*x =%^
%%44 %%40 %%54 %%50 %%64 %%60 %%74 %%70^") do^
set $=%%!%%1:~0%%300%%!%F%%F%%F%%F%%F%%F%%F%%F%%F%%F%%F%%F%%F%%F%%F%%F%^
%$:0=F%%$:0=E%%$:0=D%%$:0=C%%$:0=B%%$:0=A%%$:0=9%%$:0=8%^
%$:0=7%%$:0=6%%$:0=5%%$:0=4%%$:0=3%%$:0=2%%$:0=1%%$%^&^
for %%$ in (0%%300+0x0%%!$:~511%%#,1%%!%%!$:~255%%#,1%%!) do^
(if %%? lss ' endlocal)^&(set /A %%2=%%$^
) else (if %%? GTR ' setlocal enabledelayedexpansion)^&set $args=
for %%i in (i o F $) do set "%%i="
@goto :eof
Code: Select all
Check length str1 gtr 8190 X
~~~~~~~~~~~~~~~~~~~~
"2v TEST"
Delayed ON
Functional test 0 ... 8189 + 8191 with Delayedexpansion ON (create macro)
04.93
04.48
04.48
Delayed OFF
Functional test 0 ... 8189 + 8191 with Delayedexpansion OFF (create macro)
04.50
04.50
04.50
~~~~~~~~~~~~~~~~~~~~
"2w TEST"
Delayed ON
Functional test 0 ... 8189 + 8191 with Delayedexpansion ON (create macro)
05.05
05.05
05.05
Delayed OFF
Functional test 0 ... 8189 + 8191 with Delayedexpansion OFF (create macro)
05.03
05.04
05.03
~~~~~~~~~~~~~~~~~~~~
"2x TEST"
Delayed ON
Functional test 0 ... 8189 + 8191 with Delayedexpansion ON (create macro)
05.25
05.25
05.27
Delayed OFF
Functional test 0 ... 8189 + 8191 with Delayedexpansion OFF (create macro)
05.25
05.23
05.24
~~~~~~~~~~~~~~~~~~~~
"2y TEST"
Delayed ON
Functional test 0 ... 8189 + 8191 with Delayedexpansion ON (create macro)
05.50
05.49
05.50
Delayed OFF
Functional test 0 ... 8189 + 8191 with Delayedexpansion OFF (create macro)
05.39
05.42
05.42
~~~~~~~~~~~~~~~~~~~~
"All Batch and CMDline"
Delayed ON
Functional test 0 ... 8189 + 8191 with Delayedexpansion ON (create macro)
04.55
04.55
04.56
Delayed OFF
Functional test 0 ... 8189 + 8191 with Delayedexpansion OFF (create macro)
04.56
04.56
04.58
done
Delayed OFF
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I x8400 I all I 2v I 2w I 2x I 2y I 2a I 2b I all I
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I 8191 I 02.92 I 01.99 I 02.02 I 02.00 I 02.08 I 02.14 I 02.19 I 02.01 I
I 0 I 02.95 I 02.00 I 02.04 I 02.07 I 02.07 I 02.16 I 02.19 I 02.01 I
I 6000 I 03.10 I 02.11 I 02.18 I 02.17 I 02.20 I 02.27 I 02.31 I 02.12 I
I 4000 I 03.04 I 02.06 I 02.13 I 02.14 I 02.17 I 02.24 I 02.25 I 02.09 I
I 4500 I 03.08 I 02.11 I 02.13 I 02.14 I 02.17 I 02.23 I 02.28 I 02.11 I
I 1000 I 02.99 I 02.03 I 02.06 I 02.07 I 02.09 I 02.17 I 02.20 I 02.04 I
I 600 I 02.99 I 02.02 I 02.08 I 02.06 I 02.09 I 02.17 I 02.21 I 02.05 I
I 200 I 02.98 I 02.03 I 02.07 I 02.06 I 02.09 I 02.14 I 02.18 I 02.03 I
I 10 I 02.95 I 02.00 I 02.07 I 02.04 I 02.10 I 02.15 I 02.19 I 02.05 I
I 1 I 02.97 I 02.00 I 02.05 I 02.04 I 02.08 I 02.16 I 02.17 I 02.01 I
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I x8400 I all I 2v I 2w I 2x I 2y I 2a I 2b I all I
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I 5412 I 03.10 I 02.10 I 02.15 I 02.14 I 02.21 I 02.26 I 02.28 I 02.10 I
I 8026 I 03.17 I 02.17 I 02.21 I 02.22 I 02.30 I 02.28 I 02.33 I 02.16 I
I 2194 I 03.01 I 02.03 I 02.10 I 02.10 I 02.13 I 02.19 I 02.22 I 02.04 I
I 4229 I 03.08 I 02.09 I 02.13 I 02.13 I 02.17 I 02.22 I 02.27 I 02.10 I
I 7246 I 03.13 I 02.15 I 02.17 I 02.20 I 02.21 I 02.30 I 02.33 I 02.16 I
I 690 I 02.99 I 02.03 I 02.06 I 02.06 I 02.11 I 02.14 I 02.20 I 02.03 I
I 5178 I 03.09 I 02.09 I 02.14 I 02.15 I 02.19 I 02.24 I 02.28 I 02.09 I
I 3009 I 03.02 I 02.07 I 02.09 I 02.08 I 02.13 I 02.21 I 02.25 I 02.08 I
I 4674 I 03.08 I 02.09 I 02.14 I 02.12 I 02.16 I 02.24 I 02.27 I 02.07 I
I 800 I 02.97 I 02.02 I 02.05 I 02.03 I 02.10 I 02.17 I 02.22 I 02.03 I
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I x8400 I all I 2v I 2w I 2x I 2y I 2a I 2b I all I
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
I 59 I 02.97 I 02.00 I 02.04 I 02.05 I 02.08 I 02.16 I 02.20 I 02.02 I
I 774 I 02.97 I 02.03 I 02.05 I 02.05 I 02.08 I 02.16 I 02.20 I 02.00 I
I 4284 I 03.06 I 02.08 I 02.14 I 02.14 I 02.16 I 02.24 I 02.26 I 02.08 I
I 6160 I 03.09 I 02.09 I 02.15 I 02.16 I 02.21 I 02.26 I 02.31 I 02.13 I
I 6320 I 03.11 I 02.13 I 02.16 I 02.17 I 02.20 I 02.26 I 02.30 I 02.11 I
I 6950 I 03.11 I 02.16 I 02.15 I 02.16 I 02.20 I 02.25 I 02.29 I 02.13 I
I 3621 I 03.03 I 02.11 I 02.13 I 02.11 I 02.16 I 02.20 I 02.21 I 02.08 I
I 4032 I 03.06 I 02.06 I 02.11 I 02.12 I 02.18 I 02.22 I 02.28 I 02.09 I
I 7713 I 03.15 I 02.14 I 02.19 I 02.18 I 02.23 I 02.25 I 02.29 I 02.14 I
I 4247 I 03.04 I 02.08 I 02.12 I 02.11 I 02.16 I 02.24 I 02.25 I 02.06 I
+--------+--------+--------+--------+--------+--------+--------+--------+--------+
Drücken Sie eine beliebige Taste . . .
Code: Select all
for /f tokens^=15delims^=^ %%3 ...
Code: Select all
for /f "tokens=15 delims= " %%3 ...
Code: Select all
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLen
:: Computes the number of resulting UTF-16 code units in a string.
:: %strLen% str [len]
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out, Optional] Name of the variable that receives the measured
:: length. If omitted, the result is assigned to variable len.
:: Variable names must be passed unquoted.
:: Strings of up to 8191 characters are supported.
%== ! -> exclamation mark, # -> caret ==% FOR /F "TOKENS=1-3" %%! IN (
"! ! ^ ^^^! . ^!=^!^^^^"
%== _ -> backspace (used as delimiter) ==% ) DO FOR /F %%_ IN (
'"PROMPT $H&FOR %%B IN (1) DO REM"'
) DO FOR %%H IN (FEDCBA9876543210) DO ^
set strLen=^
%==% for /f %%? in ("%%! '") do for %%. in (1 2) do if %%.==2^
%= =% for /f "tokens=1,2" %%1 in ("%%!$args%%! len") do^
%= =% if not defined %%1 ((if %%? lss ' endlocal)^&set /a %%2=0)^
%= =% else for /f "tokens=4,8,12,16 delims=%%_" %%4 in (^"^
%= =%%%!%%1:~2047,1%%!%%_%%!%%1:~4095,1%%!%%_%%!%%1:~6143,1%%!%%_^
%= =%17%%_13%%_7%%_3%%_16%%_12%%_6%%_2%%_^
%= =%15%%_11%%_5%%_1%%_14%%_10%%_4%%_0^"^
%= =% ) do for /f "tokens=8 delims=%%_" %%3 in (^"^
%= =%%%!%%1:~0%%7777,1%%!%%_%%!%%1:~0%%7377,1%%!%%_^
%= =%%%!%%1:~0%%6777,1%%!%%_%%!%%1:~0%%6377,1%%!%%_^
%= =%%%!%%1:~0%%5777,1%%!%%_%%!%%1:~0%%5377,1%%!%%_%%!%%1:~0%%4377,1%%!%%_^
%= =%%%44%%_%%40%%_%%54%%_%%50%%_%%64%%_%%60%%_%%74%%_%%70^"^
%= =% ) do set $=%%!%%1:~0%%300%%!^
%= =%%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H^
%= =%FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
%= =%BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
%= =%7777777777777777666666666666666655555555555555554444444444444444^
%= =%3333333333333333222222222222222211111111111111110000000000000000^&^
%= =% for %%- in (0%%300+0x0%%!$:~511%%#,1%%!%%!$:~255%%#,1%%!) do^
%= =% ((if %%? lss ' endlocal)^&set /a %%2=%%-)^
%==% else (if %%? gtr ' setlocal enabledelayedexpansion)^&set $args=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
IMHO a bad idea, a function should do what it claims.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
>nul chcp 65001
call :initStrLen
set "str=🙋🏻♂️"
echo %str%
%strLen% str len
echo length: %len%
pause
exit /b
:: macro initialization here ...
Code: Select all
/? !;:"(!^^ %%)@&%1^"*,><+
Huh? Did we really define that?our general default test string
Code: Select all
:: make sure we are in the spotlight:
@if "%~1"=="" start /realtime conhost "%~f0" 1&exit /b
@echo off &setlocal DisableDelayedExpansion
:: 33
set "str0=&<>|^-+*/~!%%=?.,:;#$'`\][}{)(_@ ""
:: 8191
::16 32 64 128 256 512 1024 2048 4096 carets and one "test character"
call call call call call call call call call set "str1=^^^^^^^^x"
set "str1=%str1:~1%"
:: replace the carets with two "test characters" each
set str1=^
%str1:^=xx%
:: 7000
set "str2=%str1:~,7000%"
:: 4096
set "str3=%str1:~,4096%"
:: 4095
set "str4=%str1:~,4095%"
:: 1000
set "str5=%str1:~,1000%"
:: 256
set "str6=%str1:~,256%"
:: 255
set "str7=%str1:~,255%"
:: 100
set "str8=%str1:~,100%"
:: 10
set "str9=%str1:~,10%"
:: 1
set "str10=%str1:~,1%"
:: 0
set "str11="
call :initTimediff
:: comment this or leave it ...
setlocal EnableDelayedExpansion
echo #83
call :initStrLen
call :test str0
call :test str1
call :test str2
call :test str3
call :test str4
call :test str5
call :test str6
call :test str7
call :test str8
call :test str9
call :test str10
call :test str11
pause
exit /b
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initStrLen
:: Computes the number of resulting UTF-16 code units in a string.
:: %strLen% str [len]
:: str - [ByRef In] Name of the variable containing the string to be measured.
:: len - [ByRef Out, Optional] Name of the variable that receives the measured
:: length. If omitted, the result is assigned to variable len.
:: Variable names must be passed unquoted.
:: Strings of up to 8191 characters are supported.
%== ! -> exclamation mark, # -> caret ==% FOR /F "TOKENS=1-3" %%! IN (
"! ! ^ ^^^! . ^!=^!^^^^"
%== _ -> backspace (used as delimiter) ==% ) DO FOR /F %%_ IN (
'"PROMPT $H&FOR %%B IN (1) DO REM"'
) DO FOR %%H IN (FEDCBA9876543210) DO ^
set strLen=^
%==% for /f %%? in ("%%! '") do for %%. in (1 2) do if %%.==2^
%= =% for /f "tokens=1,2" %%1 in ("%%!$args%%! len") do^
%= =% if not defined %%1 ((if %%? lss ' endlocal)^&set /a %%2=0)^
%= =% else for /f "tokens=4,8,12,16 delims=%%_" %%4 in (^"^
%= =%%%!%%1:~2047,1%%!%%_%%!%%1:~4095,1%%!%%_%%!%%1:~6143,1%%!%%_^
%= =%17%%_13%%_7%%_3%%_16%%_12%%_6%%_2%%_^
%= =%15%%_11%%_5%%_1%%_14%%_10%%_4%%_0^"^
%= =% ) do for /f "tokens=8 delims=%%_" %%3 in (^"^
%= =%%%!%%1:~0%%7777,1%%!%%_%%!%%1:~0%%7377,1%%!%%_^
%= =%%%!%%1:~0%%6777,1%%!%%_%%!%%1:~0%%6377,1%%!%%_^
%= =%%%!%%1:~0%%5777,1%%!%%_%%!%%1:~0%%5377,1%%!%%_%%!%%1:~0%%4377,1%%!%%_^
%= =%%%44%%_%%40%%_%%54%%_%%50%%_%%64%%_%%60%%_%%74%%_%%70^"^
%= =% ) do set $=%%!%%1:~0%%300%%!^
%= =%%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H%%H^
%= =%FFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCC^
%= =%BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAAA99999999999999998888888888888888^
%= =%7777777777777777666666666666666655555555555555554444444444444444^
%= =%3333333333333333222222222222222211111111111111110000000000000000^&^
%= =% for %%- in (0%%300+0x0%%!$:~511%%#,1%%!%%!$:~255%%#,1%%!) do^
%= =% ((if %%? lss ' endlocal)^&set /a %%2=%%-)^
%==% else (if %%? gtr ' setlocal enabledelayedexpansion)^&set $args=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:initTimediff
for /f %%! in ("! ^! ^^^!") do ^
set timediff=for /l %%# in (1 1 2) do if %%#==2 for /f "tokens=2" %%$ in ("%%!%%! 1 0") do ((if 1==%%$ setlocal EnableDelayedExpansion)^&for /f "tokens=1-3" %%- in ("%%!_i_%%!") do (set "_t1_=%%!%%~-: =0%%!"^&set "_t2_=%%!%%~.: =0%%!"^&^
set /a "_d_=(8640000+(((1%%!_t2_:~,2%%!*60+1%%!_t2_:~3,2%%!)*60+1%%!_t2_:~6,2%%!)*100+1%%!_t2_:~-2%%!-36610100)-(((1%%!_t1_:~,2%%!*60+1%%!_t1_:~3,2%%!)*60+1%%!_t1_:~6,2%%!)*100+1%%!_t1_:~-2%%!-36610100))%%8640000,_o_=100000000+(_d_%%100),_d_/=100,_o_+=(_d_%%60)*100,_d_/=60,_o_+=(_d_%%60)*10000+_d_/60*1000000"^&^
set "_o_=%%!_o_:~1,2%%!:%%!_o_:~3,2%%!:%%!_o_:~5,2%%!.%%!_o_:~-2%%!"^&for /f %%' in ("%%!_o_%%!") do ((if 1==%%$ endlocal)^&if "%%~/"=="" (echo %%') else set "%%~/=%%'"))) else set _i_=
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:test
echo(
set t1=%time%
for /l %%i in (1 1 5000) do %strLen% %1 len
set t2=%time%
echo %len%
%timediff% t1 t2 diff
echo %diff%
set t1=%time%
for /l %%i in (1 1 5000) do %strLen% %1 len
set t2=%time%
echo %len%
%timediff% t1 t2 diff
echo %diff%
set t1=%time%
for /l %%i in (1 1 5000) do %strLen% %1 len
set t2=%time%
echo %len%
%timediff% t1 t2 diff
echo %diff%
set t1=%time%
for /l %%i in (1 1 5000) do %strLen% %1 len
set t2=%time%
echo %len%
%timediff% t1 t2 diff
echo %diff%
goto :eof
Something like this would be great: OpenVMS has lexical functions which could be used in DCL. See examples: https://wiki.vmssoftware.com/Category:Lexical_FunctionsaGerman wrote: ↑22 Aug 2025 11:11Bonus chatter:
It's absurd what we need to do just to perform such a simple operation. What happens in the implementation if something like !var:~N,1! is evaluated? We can rely on getting an empty result if N exceeds the string length. It does never read behind the string end into foreign memory. This can only be ensured if the length of var was known before. Think about how many times the string is measured behind the scenes when our code is executed. And think oubout how cheap it was if the CMD would support something like SET /L or whatever internal command to measure the length by either using a tight loop or by calling out to wcslen() ...
Steffen
Code: Select all
set str=some string
set str_len=f$length(str)
echo string length: %str_len%
Code: Select all
REM "" for current process, for other processes privileges are required of coruse, use real PID to get that PID's info. Item could be many things (see link above. For example USERNAME of that process...
REM F$GETJPI(pid,item)
set pid=F$GETJPI("","PID")
echo PID=%pid%
set un=F$GETJPI("1234","USERNAME")
echo un=%un%