批处理 - 变量转换为大写 [英] Batch - Converting variable to uppercase

查看:261
本文介绍了批处理 - 变量转换为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么会去改变的 destl 变量在使用前要大写。我认为某种角色互换的,但我无法得到它的工作。 code如下 -

How would I go about changing the destl variable to uppercase before it is used. I assume some sort of character swap, however I couldn't get it working. Code is as follows -

@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

我已经打过电话类似于以下,但不能得到它的工作 -

I have tried calling something like the following, but could not get it to work -

: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!

很抱歉的粗糙code - 我很新的这

Sorry about the rough code - I'm quite new to this.

问候,

约书亚

推荐答案

的捷径(无需第三方下载)是使用PowerShell的。

The shortest way (without requiring 3rd party downloads) would be to use PowerShell.

set "str=The quick brown fox"
for /f "usebackq delims=" %%I in (`powershell "\"%str%\".toUpper()"`) do set "upper=%%~I"

有一个更快的方法,但仍使用更少code比单纯批次的解决方案是采用WSH。

A faster way but still using less code than any pure batch solution would be to employ 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());

当然,你可以很容易地无论是功能,让您可以呼叫根据需要对其进行多次。

And of course, you can easily make either a function so you can call it multiple times as needed.

@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());


或者,如果你想成为真正hacksy的话,你可能会滥用命令的错误信息是这样的:


Or if you want to be really hacksy about it, you could abuse the tree command's error message like this:

@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%

这篇关于批处理 - 变量转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆