批处理 大小写转换

@ECHO OFF
SET "UP=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 "DOWN=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 STR="falfFDFvlSDF.SDFckGmsSDFz;lJf ehmKsd"
::需要引号包含否则无法传入空格分号
ECHO 原始字符串: %STR%

CHOICE /N /C UD /M "转换大写 U, 转换小写 D:"

	IF ERRORLEVEL 2 ( CALL :DOWNCASE %STR% RESULT ) ELSE (
		IF ERRORLEVEL 1 CALL :UPCASE %STR% RESULT
	)


ECHO 转换后字符串: %RESULT%
PAUSE
GOTO :EOF

:UPCASE
ECHO UPCASE
SETLOCAL ENABLEDELAYEDEXPANSION
SET $=&SET "#=%~1"
ECHO %#%
IF DEFINED # (
	FOR %%A IN (%UP%) DO SET #=!#:%%A=%%A!
)
ENDLOCAL&SET "%~2=%#%"&EXIT/B

:DOWNCASE
ECHO DOWNCASE
SETLOCAL ENABLEDELAYEDEXPANSION
SET $=&SET "#=%~1"
IF DEFINED # (
	FOR %%A IN (%DOWN%) DO SET #=!#:%%A=%%A!
)
ENDLOCAL&SET "%~2=%#%"&EXIT/B

你可能感兴趣的:(BATCH)