如何批量获取子字符串在字符串中的位置 [英] How to get position of the sub string in string in batch
本文介绍了如何批量获取子字符串在字符串中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取子字符串的位置,
Set str1=This is Test string
Set sstr=Test
在这里,我需要获得测试"(8)的位置.
Here i need to get the position of "Test"(8).
谢谢...
推荐答案
@echo OFF
SETLOCAL
Set "str1=This is Test string"
Set "sstr=Test"
SET stemp=%str1%&SET pos=0
:loop
SET /a pos+=1
echo %stemp%|FINDSTR /b /c:"%sstr%" >NUL
IF ERRORLEVEL 1 (
SET stemp=%stemp:~1%
IF DEFINED stemp GOTO loop
SET pos=0
)
ECHO Pos of "%sstr%" IN "%str1%" = %pos%
(返回"9",将第一个位置计为"1".定义在用户的脑海中...)
(This returns "9", counting the first position as "1". The definition is in the mind of the user...)
这篇关于如何批量获取子字符串在字符串中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文