How to split string without for loop in batch file

前端 未结 6 929
暗喜
暗喜 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条回答
  •  抹茶落季
    2020-12-06 06:03

    Here's a solution without nasty tricks for leading piece

        REM accepts userID@host
        setlocal enableDelayedExpansion
        set "str=%1"
        set "host=%str:*@=%"
        for /F "tokens=1 delims=@" %%F IN ("%str%") do set "user=%%F"
        echo user@host = %user%@%host%
        endlocal
    

提交回复
热议问题