How to split string without for loop in batch file

前端 未结 6 942
暗喜
暗喜 2020-12-06 05:33

I want to split a string in two parts, without using any for loop.

For example, I have the string in a variable:

str=45:abc

I want

6条回答
  •  Happy的楠姐
    2020-12-06 06:19

    You can try this . If its fixed that numbers to left of the colon will be always 2 & to the right will be 3. Then following code should work assuming your str has the value.

    set "str=45:abc"
    echo %str%
    set var1=%str:~0,2%
    set var2=%str:~3,3%
    echo %var1% %var2%
    

    Keep me posted. :)

提交回复
热议问题