本文介绍了如何提取的批处理文件的子串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我需要让子上形成的批处理文件字符串

我有这种

 设置path =C:\\测试\\分支机构\\ 9.1 \\ _build

我需要得到分支值之后的第一个值: 9.1

但这个值可以像其他位置

  C:\\ XXX \\ YYYY \\ ZZZZ \\分支机构\\ otherbranch \\ ZZZ \\ UUUU \\ III

在这种情况下,我需要得到这样的: otherbranch
我需要一个通用的解决方案,谢谢你们..


解决方案

 将mypath中= C:\\测试\\分支机构\\ 9.1 \\ _build
设置值=%mypath中:* \\分支机构\\ =%
如果%值%==%mypath中%回声\\分支机构\\找不到&放大器;转到:EOF
FOR / Fdelims = \\%%一中(%值%)并设置值= %%〜一
回声%值%

Now I need get the substring form a string on batch File

I have this

set path="c:\test\branches\9.1\_build"

I need get the first value after the branches value : 9.1

But this value can be in other position like

c:\xxx\yyyy\zzzz\branches\otherbranch\zzz\uuuu\iii

In this case, I need get this: otherbranchI need one generic solution, Thank you guys..

解决方案
set "mypath=c:\test\branches\9.1\_build"
set "value=%mypath:*\branches\=%"
if "%value%"=="%mypath%" echo "\branches\" not found &goto :eof
for /f "delims=\" %%a in ("%value%") do set "value=%%~a"
echo %value%

这篇关于如何提取的批处理文件的子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 21:16