Replace a substring using position string substitution

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Replace a substring using position string substitution

#1 Post by darioit » 17 May 2016 01:43

Hello,
I find this script for string substitution

Code: Select all

set str=teh cat in teh hat
echo.%str%
set str=%str:teh=the%
echo.%str%


How can I modify this script specifying a string position, in this case change string "teh" if it found only a position 11,3

Thank you

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Replace a substring using position string substitution

#2 Post by aGerman » 17 May 2016 04:11

You may try

Code: Select all

if "%str:~11,3%"=="teh" set "str=%str:~,11%the%str:~14%"

Regards
aGerman

Post Reply