有文本a.txt如下:
aaaaaaa aaaa bbbbbb ccccccccccc dddd
aa aaaaaaa bbbbbbbb cccccccccc ddddddddddddd eeeeeee
aaaaaaaaaaaa bbbbbbbbbbb cccccccccccccccccccc
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aa
aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbb
aaaaaaaaa ccccccccc bbbbbbbbbbbbb ddddddddddddddddd
通过批处理查找出文本中字符数(不含空格)最多的行并输出,很明显就是复制内容到剪贴板代码:
aaaaaaaaa ccccccccc bbbbbbbbbbbbb ddddddddddddddddd
要求:
1 不生成临时文件
2 代码简洁,高效,通用性好
3 加分仍以思路为重
浅默:
复制代码 代码如下:
@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+=1goto 1
if %m% gtr %n% set n=%m%set wang=%ke%
goto :eof
batman:
复制代码 代码如下:
@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%个字符
pause>nulgoto :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"