本帖最后由 WHY 于 2019-6-18 22:29 编辑
批处理 for 循环里面只能 goto 到循环外部,不能在 for 循环内部 goto
这样应该可以:- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('type 1.txt') do (
- set "var=%%i"
- for /l %%a in (1,1,99) do (
- set "var1=!var:~0,%%a!"
- set "var2=!var:~%%a!"
- if "!var1!" == "!var2!" (echo;!var1!)
- )
- )
- pause
复制代码 或者试试 call :标签- @echo off
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('type 1.txt') do (
- call :GetString "%%i"
- )
- pause & goto :EOF
-
- :GetString
- set "var=%~1"
- for /l %%a in (1,1,99) do (
- set "var1=!var:~0,%%a!"
- set "var2=!var:~%%a!"
- if "!var1!" == "!var2!" (echo;!var1!&goto :EOF)
- )
复制代码
|