CMD: piping ECHO to SET/ expanding variables in variables

后端 未结 3 674
小蘑菇
小蘑菇 2021-01-27 09:58

%x:~12,3% Returns 3 characters starting at the 12:th character in x variable. What I have been trying to accomplish is using variables instead of 12 an

3条回答
  •  一生所求
    2021-01-27 10:28

    You need to enable delayed expansion.

    @echo off
    setlocal enabledelayedexpansion
    
    set string=1234567890abcdef
    set substring_start=12
    set substring_length=3
    
    set substring=!string:~%substring_start%, %substring_length%!
    set command=echo !substring!
    
    !command!
    pause
    

提交回复
热议问题