Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
pieh-ejdsch
- Posts: 259
- Joined: 04 Mar 2014 11:14
- Location: germany
#91
Post
by pieh-ejdsch » 24 Aug 2025 14:24
The EOL of the for loop is a semicolon (;).
If the first character is a semicolon, the loop will not be executed.
Therefore, the first token character must not be a semicolon.
Alternatively, the EOL must be set to empty.
Code: Select all
for /f tokens%%#=4%%#,8%%#,12%%#,16delims%%#=%%_%%# eol%%#= %%4 in ...
-
aGerman
- Expert
- Posts: 4748
- Joined: 22 Jan 2010 18:01
- Location: Germany
#92
Post
by aGerman » 24 Aug 2025 14:53
I could have sworn that I tested it
Fixed.
A minor update is that it now uses a US as delimiter. It's nowhere used anymore. However, we meet its original semantics if we take it for this purpose. Perhaps this is something that jeb feels more comfortable with. The downside is that the macro initialization is getting even more expensive now. It increases the break-even point for the number of strings measured at which something like this still makes sense.
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 (
"! ! ^ ^^^! . ^!=^!^^^^"
%== _ -> Unit Separtor (ASCII 31) ==% ) DO FOR /F %%_ IN (
'FORFILES.EXE /P "%__APPDIR__%." /M "CMD.EXE"^
/C "CMD.EXE /Q /D /C ECHO(0x1F"'
) 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=5,9,13,17 delims=%%_" %%4 in (^"^
%= =%X%%_%%!%%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=9 delims=%%_" %%3 in (^"^
%= =%X%%_%%!%%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
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::