How to convert the value of %USERNAME% to lowercase within a Windows batch script?

后端 未结 9 615
暗喜
暗喜 2020-12-09 17:10

I\'m automating some source control software functionality using a dot bat script but given that our svn repos are hosted in a *NIX box, I\'m facing the eternal case problem

9条回答
  •  没有蜡笔的小新
    2020-12-09 17:26

    Probably this is the fastest way to convert a string to lowercase in batch file as it uses macro and there are no temp files (it saves the produced string in variable called result):

    @echo off
    
    set LowerCaseMacro=for /L %%n in (1 1 2) do if %%n==2 (for %%# in (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) do set "result=!result:%%#=%%#!") else setlocal enableDelayedExpansion ^& set result=
    
    set "string=SOme STrinG WiTH lowerCAse letterS and UPCase leTTErs"
    %LowerCaseMacro%%string%
    
    echo %result%
    

提交回复
热议问题