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

Time:2020-8-1

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

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

Silence:

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%
pause
goto :eof
:1
if not “!ke1:~%m%,1!”==”” set /a m+=1&goto 1
if %m% gtr %n% set n=%m%&set wang=%ke%
goto :eof

 

batman:

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
:lp
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”