Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

batch file - how to select exactly part of a number as a simple character and exclude all the rest in CMD?

i will explain below what i want to do with CMD

I have this name of file:

set "File=0119315314"

with 2 in 2, i want to separete file name as this line: 01 19 31 53 14

the problem here, is the number 31 because of "53" and "14" when its joined, we have "5314" and looks the mirror of "31" into "5314"

i tryed it:

set "New=%File:31=%"

when i exclude the number "31" I burn the characters "5314" too now, i dont get "53" and "14" for my sequence: 01 19 31 53 14

you undestand? Please, how to solve it? is possible?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If I understand correctly, perhaps you're looking for something like this:

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

Set "f=0119315314"

Set "i=0"
For /F Delims^=^ EOL^= %%G In (
    '%__AppDir__%cmd.exe /U/D/C Echo(!f!^|%__AppDir__%find.exe /V ""') Do (
    Set /A "i+=1, m=i%%2"
    If !m! Equ 0 (Set "s=!s!%%G ") Else Set "s=!s!%%G")
If %m% Equ 0 Set "s=%s:~,-1%"

Echo(%s%

Pause

Expected result:

01 19 31 53 14

Or perhaps you're looking for something a little simpler:

@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

Set "f=0119315314"

For /L %%G In (0,2,20) Do If Not "!f:~%%G,2!" == "" Echo(!f:~%%G,2!

Pause

Expected output:

01
19
31
53
14

In this example you can increase 20 if you intend to use a string of more than twenty characters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...