我在这里toUpper
和 stackoverflow 上找到了用于批处理文件的字符串函数,但我不知道如何使用它们。我找到了几个示例和说明,其中一些是矛盾的,但出于某种原因,它们对我都不起作用。我如何在 .bat 文件中使用这样的函数?以下是示例代码:toUpper
@echo off
setlocal enabledelayedexpansion
:: Main script starts here
set "arg=exampleString"
:: Output the original
echo Original: %arg%
:: Call the toUpper function to convert %arg% to uppercase
call :toUpper arg
:: Output the result
echo Uppercase: %arg%
EXIT /b 1
:toUpper str -- converts lowercase character to uppercase
if not defined %~1 EXIT /b
for %%a in ("a=A" "b=B" "c=C" "d=D" "e=E" "f=F" "g=G" "h=H" "i=I"
"j=J" "k=K" "l=L" "m=M" "n=N" "o=O" "p=P" "q=Q" "r=R"
"s=S" "t=T" "u=U" "v=V" "w=W" "x=X" "y=Y" "z=Z" "ä=Ä"
"ö=Ö" "ü=Ü") do (
call set %~1=%%%~1:%%~a%%
)
EXIT /b
我得到的是:
Original: exampleString
Uppercase: "ü=Ü"rg:ü=Ü
这里发生了什么事?
编辑:添加了缺失的返回语句(请参阅评论以回答)