| 1 | + | @echo off |
| 2 | + | goto :end_remarks |
| 3 | + | ************************************************************************************* |
| 4 | + | * |
| 5 | + | * |
| 6 | + | * authored:Sam Wofford |
| 7 | + | * Returns lowercase of a string |
| 8 | + | * 12:13 PM 11/13/02 |
| 9 | + | ************************************************************************************** |
| 10 | + | :end_remarks |
| 11 | + | setlocal |
| 12 | + | set errorlevel=-1 |
| 13 | + | if {%1}=={} echo NO ARG GIVEN&call :Help &goto :endit |
| 14 | + | if {%1}=={/?} call :Help &goto :endit |
| 15 | + | 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 |
| 16 | + | |
| 17 | + | :start |
| 18 | + | set input=%1 |
| 19 | + | set input=%input:"=% |
| 20 | + | set totparams=0 |
| 21 | + | call :COUNT_PARAMS %input% |
| 22 | + | call :MAKE_LOWERCASE %input% |
| 23 | + | set errorlevel= |
| 24 | + | echo %convertedstring% |
| 25 | + | endlocal |
| 26 | + | goto :eof |
| 27 | + | :endit |
| 28 | + | echo %errorlevel% |
| 29 | + | endlocal |
| 30 | + | goto :eof |
| 31 | + | |
| 32 | + | :MAKE_LOWERCASE |
| 33 | + | :nextstring |
| 34 | + | if {%1}=={} goto :eof |
| 35 | + | set string=%1 |
| 36 | + | set /a params+=1 |
| 37 | + | set STRINGCONVERTED= |
| 38 | + | set pos=0 |
| 39 | + | :NEXT_CHAR |
| 40 | + | set onechar=%%string^:^~%pos%,1%% |
| 41 | + | for /f "tokens=1,2 delims==" %%a in ('set onechar') do for /f %%c in ('echo %%b') do call :checkit %%c |
| 42 | + | if not defined STRINGCONVERTED goto :NEXT_CHAR |
| 43 | + | shift /1 |
| 44 | + | if %params% LSS %totparams% set convertedstring=%convertedstring% &:add one space,but not at end |
| 45 | + | goto :nextstring |
| 46 | + | goto :eof |
| 47 | + | |
| 48 | + | :Help |
| 49 | + | echo USAGE:%~n0 string OR %~n0 "with spaces" |
| 50 | + | echo function returns the lowercase of the string or -1 (error) |
| 51 | + | echo strings with embedded spaces needs to be in quotes Ex. "lower case" |
| 52 | + | echo in a batch NTscript "for /f %%%%A in ('lcase STRING') do set var=%%%%A" |
| 53 | + | set errorlevel= |
| 54 | + | goto :eof |
| 55 | + | |
| 56 | + | :checkit |
| 57 | + | set LCFOUND= |
| 58 | + | if /i {%1}=={echo} set STRINGCONVERTED=Y&goto :eof |
| 59 | + | set char=%1 |
| 60 | + | for /f "tokens=2 delims=_=" %%A in ('set LCASE_') do call :findit %%A %char% |
| 61 | + | :skipit |
| 62 | + | if defined LCFOUND (set convertedstring=%convertedstring%%ucletter%) else (set convertedstring=%convertedstring%%char%) |
| 63 | + | set /a pos+=1 |
| 64 | + | goto :eof |
| 65 | + | |
| 66 | + | :set_LCASE_array |
| 67 | + | :setit |
| 68 | + | if {%1}=={} goto :eof |
| 69 | + | set LCASE_%1_=%1 |
| 70 | + | SHIFT /1 |
| 71 | + | goto :setit |
| 72 | + | |
| 73 | + | :findit |
| 74 | + | if defined LCFOUND goto :eof |
| 75 | + | set ucletter=%1 |
| 76 | + | set lcchar=%2 |
| 77 | + | if /i {%ucletter%}=={%lcchar%} set LCFOUND=yes |
| 78 | + | goto :eof |
| 79 | + | |
| 80 | + | :COUNT_PARAMS |
| 81 | + | :COUNTPARAMS |
| 82 | + | if {%1}=={} goto :eof |
| 83 | + | set /a totparams+=1 |
| 84 | + | shift /1 |
| 85 | + | goto :COUNTPARAMS |
| 86 | + | |