Find index of substring or character in string.
Posted: 02 Jan 2009 16:19
Does anyone know how to find the index of a substring or character in a string?
Thanks!
Thanks!
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
setlocal
set str=abcdefghijklmnopqrstuvxyz
call :indexOf result "%str%" "e"
echo %result%
goto :eof
::::::::::::::::::::::::::::::::::::::::::::::::::::
:indexOf <resultVar> <str> <find>
SETLOCAL
set "str=%~2"
call set "part=%%str:%~3=&rem.%%"
set partB=%part%
call :strLen partB len
( ENDLOCAL
set %~1=%len%
EXIT /b
)