How to substitute variable contents in a Windows batch file

前端 未结 7 1612
栀梦
栀梦 2021-01-08 00:55

I\'m writing a simple script to substitute text in an environment variable with other text. The trouble I get is with the substituted or substituted text being pulled from o

7条回答
  •  终归单人心
    2021-01-08 01:34

    Please try the following:

    Copy and paste the code into Notepad and save it as a batch file.

       @echo off
       setlocal enabledelayedexpansion
    
       set str=The fat cat
       set f=fat
    
       echo.
       echo          f = [%f%]
    
       echo.
       echo        str = [%str%]
    
       set str=!str:%f%=thin!
    
       echo str:f=thin = [%str%]
    

    I hope you're convinced!

提交回复
热议问题