Batch - Converting variable to uppercase

前端 未结 8 1709
一向
一向 2020-12-02 01:39

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. C

8条回答
  •  [愿得一人]
    2020-12-02 02:36

    If you have any POSIX utilities installed on Windows, like many developers (e.g., GNUWin utilities at https://sourceforge.net/projects/gnuwin32/)

    You could use the tr.exe utility, which has: [:upper:]

    @echo off
    SETLOCAL EnableDelayedExpansion
    echo Before: SCEINST is: %SCEINST%
    set upper=
    for /f "usebackq delims=" %%g in (`echo %SCEINST% ^| tr [:lower:] [:upper:]`) do (
        SET upper=%%g
        :: get rid of any leading whitespace
        set upper=!upper: =!
        goto :done
    )
    :done
    echo After: SCEINST (in upper) is now: !upper!
    

    ----------OUTPUT----------

    Before: SCEINST is: scprd
    After: SCEINST (in upper) is now: SCPRD
    

提交回复
热议问题