我使用点击蝙蝠脚本自动化一些源代码控制软件功能,但鉴于我们的svn repos托管在*NIX框中,我面临着这两个世界之间的永恒案例问题.
是否有任何cmd.exe函数将Windows系统变量%USERNAME%的值转换为小写?
非常感谢!
好吧,我正在浏览一些语法,偶然发现了这个页面.我知道它已经老了,但我想我会休息一下,让大脑有点小动作.
这里的东西有点短,易于管理.这只是"强制"将所有大写字母改为小写字母,而不考虑字符串中是否存在实际字母.因此,无论字符串的长度如何,功能循环都会正好运行26次.
希望这有助于某人.
@echo off cls setlocal enabledelayedexpansion REM ***** Modify as necessary for the string source. ***** set "_STRING=%*" if not defined _STRING set "_STRING=%USERNAME%" set _STRING REM ***** Modify as necessary for the string source. ***** set "_UCASE=ABCDEFGHIJKLMNOPQRSTUVWXYZ" set "_LCASE=abcdefghijklmnopqrstuvwxyz" for /l %%a in (0,1,25) do ( call set "_FROM=%%_UCASE:~%%a,1%% call set "_TO=%%_LCASE:~%%a,1%% call set "_STRING=%%_STRING:!_FROM!=!_TO!%% ) set _STRING endlocal
例:
E:\OS.ADMIN>LCASE.BAT The Quick Fox Jumps Over The Brown Fence.
结果:
_STRING=The Quick Fox Jumps Over The Brown Fence. _STRING=the quick fox jumps over the brown fence.
一个快速的谷歌发现这 ...
@echo off goto :end_remarks ************************************************************************************* * * * authored:Sam Wofford * Returns lowercase of a string * 12:13 PM 11/13/02 ************************************************************************************** :end_remarks setlocal set errorlevel=-1 if {%1}=={} echo NO ARG GIVEN&call :Help &goto :endit if {%1}=={/?} call :Help &goto :endit call :set_LCASE_array 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 :start set input=%1 set input=%input:"=% set totparams=0 call :COUNT_PARAMS %input% call :MAKE_LOWERCASE %input% set errorlevel= echo %convertedstring% endlocal goto :eof :endit echo %errorlevel% endlocal goto :eof :MAKE_LOWERCASE :nextstring if {%1}=={} goto :eof set string=%1 set /a params+=1 set STRINGCONVERTED= set pos=0 :NEXT_CHAR set onechar=%%string^:^~%pos%,1%% for /f "tokens=1,2 delims==" %%a in ('set onechar') do for /f %%c in ('echo %%b') do call :checkit %%c if not defined STRINGCONVERTED goto :NEXT_CHAR shift /1 if %params% LSS %totparams% set convertedstring=%convertedstring% &:add one space,but not at end goto :nextstring goto :eof :Help echo USAGE:%~n0 string OR %~n0 "with spaces" echo function returns the lowercase of the string or -1 (error) echo strings with embedded spaces needs to be in quotes Ex. "lower case" echo in a batch NTscript "for /f %%%%A in ('lcase STRING') do set var=%%%%A" set errorlevel= goto :eof :checkit set LCFOUND= if /i {%1}=={echo} set STRINGCONVERTED=Y&goto :eof set char=%1 for /f "tokens=2 delims=_=" %%A in ('set LCASE_') do call :findit %%A %char% :skipit if defined LCFOUND (set convertedstring=%convertedstring%%ucletter%) else (set convertedstring=%convertedstring%%char%) set /a pos+=1 goto :eof :set_LCASE_array :setit if {%1}=={} goto :eof set LCASE_%1_=%1 SHIFT /1 goto :setit :findit if defined LCFOUND goto :eof set ucletter=%1 set lcchar=%2 if /i {%ucletter%}=={%lcchar%} set LCFOUND=yes goto :eof :COUNT_PARAMS :COUNTPARAMS if {%1}=={} goto :eof set /a totparams+=1 shift /1 goto :COUNTPARAMS
将它作为文件(lowercase.cmd)添加到您的路径中,您应该能够将其称为"Lowercase.cmd%Username%",如果需要,您可以将其管道到另一个命令中.
从http://short.stop.home.att.net/freesoft/unix.htm下载一些用于DOS的unix实用程序, 并使用tr.exe(翻译字符)
echo %USERNAME% | tr "[A-Z]" "[a-z]"
我还使用名为4NT的DOS扩展cmd替换,该替换具有内置命令@lower
echo %@lower[%USERNAME%]