:getNextInList

return next value in list

Description: call:getNextInList current list
Script:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
:getNextInList current list -- return next value in list
::                          -- current [in,out] - iterator variable holding the current value to be replaced with the next value
::                          -- list    [in]     - choice list, must start and end with the delimiter
:$created 20091207 :$changed 20091207 :$categories List,Iterate,String
:$source https://www.dostips.com
Setlocal Enabledelayedexpansion
set "lst=%~2"
set "lst=%lst:~-1%%lst%%lst:~1%"
call set "v=%%lst:*%lst:~-1%!%~1!%lst:~-1%=%%"
set "v=!v:%lst:~-1%=&rem.%!"
( ENDLOCAL & REM RETURN VALUES
    IF "%~1" NEQ "" (SET %~1=%v%) ELSE (echo.%new%)
)
GOTO:EOF


:count needle haystack ret -- counts the number of occurrences of needle in haystack
::                         -- needle   [in]  - string to find
::                         -- haystack [in]  - string to search in
::                         -- ret      [out] - valref for return value
:$created 20060101 :$changed 20090531 :$categories String
:$source https://www.dostips.com
SETLOCAL
set "haystack=%~2"
set /a ret=0
FOR /f %%a in ('"(echo.%%haystack:%~1=&echo.%%)|find /c /v """') DO set /a ret=%%a-1
( ENDLOCAL & REM RETURN VALUES
    IF "%~3" NEQ "" (SET %~3=%ret%) ELSE ECHO.%ret%
)
EXIT /b