@ECHO Off
SETLOCAL
SET "betabet=abcdefghijklmnopqrstuvwxyz1234567890!*$^&^^+=-\^|^>;'.,/?^<"
ECHO %betabet%
>u:\betabet.file ECHO %betabet%
CALL :upper betabet
ECHO %betabet%
CALL :upcase u:\betabet.file
GOTO :EOF
:upper
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 "%1=%%%1:%%a=%%a%%%"
GOTO :EOF
:upcase
setlocal EnableDelayedExpansion
for /F "delims=" %%a in (%1) do (
set "line=%%a"
for %%b 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 "line=!line:%%b=%%b!"
)
echo !line!
)
endlocal
GOTO :eof
的方法,提到了在Aacini失敗Windows batch file read text file and convert all to uppercase對於某些字符,如由上述批次證明。
如果有問題的字符串包含某些字符(例如%:
),該批次也會失敗 - 它將轉換字母,但刪除%
和:
。
上述批次首先建立一個包含雜項字符的字符串,將其顯示並保存爲文件,然後使用:upper
進行轉換。
爲了進行比較,然後使用:upcase
函數(從鏈接的響應派生)進行文件處理。
繼Aacini的有效意見和進一步的調查,這裏有一些技術(包括「讀源文件」方法的演示)
的:showline
程序存在通過顯示line
縮短代碼delayedexpansion模式
@ECHO Off
SETLOCAL
set "line=abcdefghijklmnopqrstuvwxyz1234567890|!#$%%&/\()=?<>,;.:"'_-+*~^^[]{}"
SETLOCAL enabledelayedexpansion
>u:\betabet.file ECHO "!line!"
endlocal
CALL :showline
ECHO --- show conversion using "upper - caret disappears
CALL :upper line
CALL :showline
ECHO ------------------------------
ECHO --- show actual file contents ^& data read from file
type u:\betabet.file
CALL :upcase u:\betabet.file
ECHO ------------------------------
set "line=abcdefghijklmnopqrstuvwxyz1234567890|!#$%%&/\()=?<>,;.:"'_-+*~^^[]{}"
CALL :showline
ECHO --- show conversion using "inline-conversion - caret PRESERVED
setlocal ENABLEDELAYEDEXPANSION
for %%b 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 "line=!line:%%b=%%b!"
echo "!line!" ^<--- in inline conversion
endlocal&SET "line=%line:^=^^%"
CALL :showline
ECHO ------------------------------
set "line=abcdefghijklmnopqrstuvwxyz1234567890|!#$%%&/\()=?<>,;.:"'_-+*~^^[]{}"
CALL :showline
ECHO --- show conversion using "upcase2 - caret disappears
CALL :upcase2 line
CALL :showline
GOTO :EOF
:upper
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 "%1=%%%1:%%a=%%a%%%"
GOTO :EOF
:upcase
setlocal EnableDelayedExpansion
for /F "delims=" %%a in (%1) do (
ECHO read%%a
set "line=%%a"
for %%b 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 "line=!line:%%b=%%b!"
)
echo conv!line!
)
endlocal
GOTO :eof
:upcase2
setlocal ENABLEDELAYEDEXPANSION
for %%b 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 "%1=!%1:%%b=%%b!"
endlocal&CALL SET "%1=%%%1%%"
GOTO :eof
:showline
SETLOCAL enabledelayedexpansion
ECHO "!line!"
endlocal
GOTO :eof
[此鏈接可能?](http://www.robvanderwoude.com/battech_convertcase.php) – Bloodied