Code to find the line of text with the largest number of characters in a batch


The text a.txt is as follows:
aaaaaaa aaaa bbbbbb ccccccccccc dddd
aa aaaaaaa bbbbbbbb cccccccccc ddddddddddddd eeeeeee
aaaaaaaaaaaa bbbbbbbbbbb cccccccccccccccccccc
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aa
aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbb
aaaaaaaaa ccccccccc bbbbbbbbbbbbb ddddddddddddddddd

Find the line with the largest number of characters (excluding spaces) in the text through batch processing and output it. It is obvious that the content is copied to the clipboard code:
aaaaaaaaa ccccccccc bbbbbbbbbbbbb ddddddddddddddddd

1 do not generate temporary files
The code is concise, efficient and universal
3. Emphasis on thinking


Copy codeThe code is as follows:
@echo off
Setlocal Enabledelayedexpansion
set n=0
for /f “delims=” %%i in (a.txt) do (
set “ke=%%i”
set ke1=!ke: =!
set m=0
call :1
echo %wang%
goto :eof
if not “!ke1:~%m%,1!”==”” set /a m+=1&goto 1
if %m% gtr %n% set n=%m%&set wang=%ke%
goto :eof



Copy codeThe code is as follows:
@echo off
set num=0
for /f “delims=” %%i in (a.txt) do set “str=%%i”&call,set “str=%%str: =%%”&call :lp “%%i”
call,echo %%_ %Num%%%% num% characters
pause>nul&goto :eof
set “str=%str:~1%”&set /a n+=1
if defined str goto lp
if %n% geq %num% set “num=%n%”&set “_%num%=%~1”
set “n=0”