stringbatch-fileoperations

batch: combine string operations


I'd like to combine the following string operations...

SET MYVAR=someStringWithSomeExpressionInside
SET MYVAR=%MYVAR:Expression=thing%
SET MYVAR=%MYVAR:~4%

...to something like this:

SET MYVAR=%MYVAR:Expression=thing~4%

EDIT

To give you an idea of what i'm intend to do:

SET TIMESTAMP=%DATE:~8,2%%DATE:~3,2%%DATE:~0,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
SET TIMESTAMP=%TIMESTAMP: =0%

..this should be a single SET command without any helper variables.


Solution

  • You mean like this?

    set "MYVAR=someStringWithSomeExpressionInside"
    set "MYVAR1=%MYVAR:Expression=thing%"
    set "MYVAR2=%MYVAR1:~4%"
    set "VAR=%MYVAR%%MYVAR1%%MYVAR2%"
    echo %VAR%
    

    or

    set "MYVAR=someStringWithSomeExpressionInside"
    set "VAR=%MYVAR%%MYVAR:Expression=thing%%MYVAR:~4%"
    echo %VAR%
    

    but sadly, as per you comment after I posted this. There is no single line replacement for multiple replace in batch.