3

I have an input let's say:

DummyString-v1.0.0

and I would like to extract everything after v to get: 1.0.0

How can I achieve this in CMD?

2 Answers 2

9
@ECHO OFF
SETLOCAL
SET "string=DummyString-v1.0.0"
SET "string=%string:*v=%"
ECHO %string%
GOTO :EOF

where the :*substring=replacementstring syntax is applied meaning "every character form the start of the variable (string) up to the substring (v) is replaced by the replacement string (nothing).

Sign up to request clarification or add additional context in comments.

1 Comment

You are a STAR!, very elegant solution. Just one thing though, if input has another v then this will break so I had to also add the - to address the problem. so I modified it to be: SET "string=%string:*-v=%"
1
@echo off

call :split "DummyString-v1.0.0" "v"
echo %last_part%

exit /b 0

:split

set "string=%~1"
set "splitter=%~2"

setlocal EnableDelayedExpansion
set LF=^


rem ** Two empty lines are required
echo off
for %%L in ("!LF!") DO (
    for /f "delims=" %%R in ("!splitter!") do ( 
        set "var=!string:%%R=%%L!"      
    )
)
for /f "delims=" %%P in (""!var!"") DO set "last_part=%%~P"
endlocal &(
  set last_part=%last_part%
  exit /b 0
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.