本帖最后由 迷彩的SF 于 2011-11-6 11:53 编辑
1.txt文件的内容如下:- aa
- ccccccccccccccccccccccccccccccccccccccc
- eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
- ggggggggggggggggggggggggggggggggggggggg
- wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
- zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
复制代码 我想用如下代码读取并显示每行字数:- @echo off
- setlocal enabledelayedexpansion
- set num=0
- for /f %%a in (1.txt) do (
- set num1=%%a
-
- :do
- if not "!num1:~%num%,1!" equ "" (
-
- set /a num+=1 & goto do
- ) else (
- echo The number of this sentence is %num%
- )
- echo Press any key to continue......
- pause>nul
- )
- echo;Over
- pause>nul
复制代码 但是在测试中我发现for的赋值只能执行一次,在显示 The number of this sentence is 2 之后紧接着就显示Over,随后按任意键就退出程序了,希望那位可以解释下,谢谢 |