- @echo off&setlocal enabledelayedexpansion
- set /p var=请按字母先后顺序输入两个字母:
- set var1=%var:~0,1%
- set var2=%var:~-1,1%
- set str=a b c d e f g h i j k l m n o p q r s t u v w x y z
- set count=1
- :begin
- for /f "tokens=%count%" %%i in ("!str!") do (
- set /a count+=1
- if %%i==!var1! set count1=!count!
- if %%i==!var2! set /a count2=!count!-2
- goto begin )
- echo %count1% %count2%
- set /a a=2*(count1-1)
- set /a b=2*(count2-count1+1)
- echo %a% %b%
- set str1=!str:~%a%,%b%!
- echo %str1%
- pause
复制代码 虽然很麻烦,但是结果还是正确的... |