本帖最后由 taofan712 于 2017-4-11 21:07 编辑
- @echo off&setlocal enabledelayedexpansion
- set str=bBAathToHOMmEe
- set str_bp=%str%
- for %%a in (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) do call set str_bp=%%str_bp:%%a=%%a%%
- for /l %%a in (0 1 14) do (
- for /f "tokens=1,2 delims=#" %%b in ('call echo;%%str:~%%a^,1%%#%%str_bp:~%%a^,1%%') do (
- if not "%%b"=="%%c" (set lc=!lc!%%b) else ( set uc=!uc!%%c)
- ))
- echo;!lc!!uc!
- pause
复制代码 请各位帮忙看下我的代码为什么这么慢,我原以为是用了call set和call echo,改成下面的,还是一样的慢。将近2秒。- @echo off&setlocal enabledelayedexpansion
- set str=bBAathToHOMmEe
- set str_bp=%str%
- for %%a in (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) do set str_bp=!str_bp:%%a=%%a!
- for /l %%a in (0 1 14) do (
- for /f "tokens=1,2 delims=#" %%b in ('echo;!str:~%%a^,1!#!str_bp:~%%a^,1!') do (
- if not "%%b"=="%%c" (set lc=!lc!%%b) else ( set uc=!uc!%%c)
- ))
- echo;!lc!!uc!
- pause
复制代码 @terse 感谢指点,去掉了中间一个for。- @echo off&setlocal enabledelayedexpansion
- set str=bBAathToHOMmEe
- set str_bp=%str%
- for %%a in (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) do set str_bp=!str_bp:%%a=%%a!
- for /l %%a in (0 1 14) do (
- if not "!str:~%%a,1!"=="!str_bp:~%%a,1!" (set lc=!lc!!str:~%%a,1!) else ( set uc=!uc!!str_bp:~%%a,1!)
- )
- echo;!lc!!uc!
- pause
复制代码
|