我将如何改变destl变量在使用前转换为大写。我假设某种角色交换,但我无法让它工作。代码如下——
@echo off
echo.
set /P "destf=Enter First Name: "
set /P "destl=Enter Last Name: "
set "findest=Z:\ProjectIT\copy\%destl%, %destf%"
robocopy Z:\ProjectIT\copy\test "%findest%" /e /NFL /NDL /NJH /NJS
robocopy Z:\ProjectIT\copy\Construction "%findest%"\1-BLANK-%destl% /e /NFL /NDL /NJH /NJS"
echo Construction folder has been created for "%destl%"
echo.
pause
我尝试过调用类似以下的内容,但无法让它工作 -
:Uppercase
set %~1=!%1:a=A!
set %~1=!%1:b=B!
set %~1=!%1:c=C!
set %~1=!%1:d=D!
set %~1=!%1:e=E!
set %~1=!%1:f=F!
set %~1=!%1:g=G!
set %~1=!%1:h=H!
set %~1=!%1:i=I!
set %~1=!%1:j=J!
set %~1=!%1:k=K!
set %~1=!%1:l=L!
set %~1=!%1:m=M!
set %~1=!%1:n=N!
set %~1=!%1:o=O!
set %~1=!%1:p=P!
set %~1=!%1:q=Q!
set %~1=!%1:r=R!
set %~1=!%1:s=S!
set %~1=!%1:t=T!
set %~1=!%1:u=U!
set %~1=!%1:v=V!
set %~1=!%1:w=W!
set %~1=!%1:x=X!
set %~1=!%1:y=Y!
set %~1=!%1:z=Z!
抱歉,代码很粗糙 - 我对此很陌生。
Regards,
Joshua
最短的方法(无需第三方下载)是使用 PowerShell。
set "str=The quick brown fox"
for /f "usebackq delims=" %%I in (`powershell "\"%str%\".toUpper()"`) do set "upper=%%~I"
与任何纯批处理解决方案相比,更快但使用的代码仍然更少的方法是使用 WSH。
@if (@CodeSection == @Batch) @then
@echo off & setlocal
set "str=The quick brown fox"
for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0" "%str%"') do set "upper=%%~I"
set upper
goto :EOF
@end // end Batch / begin JScript hybrid
WSH.Echo(WSH.Arguments(0).toUpperCase());
当然,您可以轻松地创建一个函数,这样您就可以call
根据需要多次。
@if (@CodeSection == @Batch) @then
@echo off & setlocal
call :toUpper upper1 "The quick brown fox"
call :toUpper upper2 "jumps over the lazy dog."
set upper
goto :EOF
:toUpper <return_var> <str>
for /f "delims=" %%I in ('cscript /nologo /e:JScript "%~f0" "%~2"') do set "%~1=%%~I"
goto :EOF
@end // end Batch / begin JScript hybrid
WSH.Echo(WSH.Arguments(0).toUpperCase());
或者,如果你想对此进行真正的黑客攻击,你可以滥用tree
命令的错误消息如下:
@echo off & setlocal
set upper=
set "str=Make me all uppercase!"
for /f "skip=2 delims=" %%I in ('tree "\%str%"') do if not defined upper set "upper=%%~I"
set "upper=%upper:~3%"
echo %upper%
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)