Get a variable-length substring based on a delimiter

I am trying to make a simple command to delete all words after a word and repeat the result.

Example:

street car-2a21340565364563563
thiswouldbedifferent-ss-3c63456345645635634
andthiscouldbesomethingelse-we-5d23453453634563456

delete all expectations in the first section

Sort of:

street car-221340565364563563

will result in:

Street

It is not saved in a txt file or anything else, is it possible?

+4
source share
1 answer

Edit: Assuming the part you are trying to extract is of variable length, this seems like an even better solution:

set str=street-ct-2a21340565364563563 for /f "delims=-" %%a in ("%str%") do set part=%%a echo.%part% 

In this snippet, we break the line whenever " - " occurs, and then assign the first part of the split line to the variable " part ". Additional examples of how to use for to separate lines can be found here .


According to this link you can do something like this:

 set str=street-ct-2a21340565364563563 set substr=%str:~0,6% echo.%substr% 
+7
source

All Articles