Page 1 of 1

Find index of substring or character in string.

Posted: 02 Jan 2009 16:19
by lstewart
Does anyone know how to find the index of a substring or character in a string?

Thanks!

Posted: 04 Jan 2009 17:59
by jeb
Hi lstewart,

try this

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
)


the :strLen function is from the DosTips-Library

hope it helps
Jan Erik

Posted: 05 Jan 2009 17:17
by lstewart
Thanks!