set cmd /E:ON
set var=asdfg
echo !var:!var:~1,1!=OK!
unfortunately don't replace s with OK , the code display
Code: Select all
!var:s=OK!
Code: Select all
aOKdfg
thank's your help .
Moderator: DosItHelp
Code: Select all
!var:s=OK!
Code: Select all
aOKdfg
Code: Select all
H:\>set var=asdfg
H:\>set var=%var:s=OK%
H:\>echo %var%
aOKdfg
Code: Select all
cmd /v:on
set var=asdfg
echo !var:~0,1!OK!!var:~2!
Code: Select all
@echo off
setlocal enableDelayedExpansion
set var=asdf
echo "!var:~0,1!OK^!!var:~2!"
echo !var:~0,1!OK^^^!!var:~2!
set "var=!var:~0,1!OK^^^!!var:~2!"
set var
Code: Select all
@echo off
setlocal disableDelayedExpansion
set var=asdf
echo %var:~0,1%OK!%var:~2%
set var=%var:~0,1%OK!%var:~2%
set var
Code: Select all
@echo off
setlocal enabledelayedexpansion
set var=asdfg
echo !var:%var:~1,1%=OK!
Code: Select all
E:\batch files\SET_example>example.bat
aOKdfg
Code: Select all
echo !var:%var:~1,1%=OK! work nice that I want, get aOKdfg
Code: Select all
echo !var:!var:~1,1!=OK! don't work, I get !var:s=OK!
For example:Aacini wrote:Code: Select all
%SET/S% variable:~start,size=substring to insert
Previous "SET-Substring" macro replace part of the current "variable" value with another substring; the part to replace is given in the same way as the standard Batch substring extraction with the sole difference that it does not end at the last character by default, so this point must be explicitly indicated by -0 in "size".
Code: Select all
REM Insert the SET/S macro definition here...
set var=asdfg
%set/s% var:~1,1=OK
echo %var%
You must note that your original code does NOT replace by position, but replaces all instances of the s letter in the string by the word OK.Result wrote:aOKdfg