This is something that is missing in grub4dos batch but that exists in NT batch:
%string:find=replace%
this script attempts to allow something similar, though not exactly the same, I am not fully convinced of its "universal" usefulness, as there are a couple issues that I seem not to be able to workaround, namely there is too much risk of an endless loop, hence a default of 1 pass, equating to "find a replace first occurence only" is implemented, that can be manually overridden with a parameter and it is not possible to use a <find> that is a subset of <replace>.
Anyway, having it sitting in my hard disk is of no use and maybe can be useful to someone (within its limits) or can be of inspiration for something better.
!BAT #str_repl function to replace string in string #analogous to (but different from) the NT batch use of %string:x=y% #parameters <string> <find> <replace> [<num of occurrencies, default 1>] #use double quotes around any of <string>, <find>, <replace> if they contain space(s) #use double quoted empty string for replace to delete <find> setlocal set str=%~1 set fnd=%~2 set /a length=%@retval%+1 > nul if %4.==. set /a cnt=1 > nul || set /a cnt=%4 > nul call Fn.11 "%str%" "%str:~0,1%" set /a base=%@retval% > nul :loop call Fn.11 "%~3" "%~2" if not %@retval%==0 set str && goto :eof call Fn.11 "%str%" "%~2" set /a left=%@retval% > nul if %left%==0 set str && goto :eof set /a left=%left%-%base% > nul call set before=%str^:~0,%left%%% set /a off=%left%+%length%-1 > nul call set after=%str^:~%off%%% set str=%before%%%~3%%after% set /a cnt=%cnt%-1 > nul if not %cnt%==0 goto :loop :output set str goto :eof
Needs to be tested and refined (and optionally transformed into an actually useful callable function).
Wonko