What seems to be happening is that subst is seeing the string ^^ or ^& as two characters, eg subst[2,^^,foobar] gives fo^ar, while subst[2,^&,foobar] gives fo&ar. This comes by that subst[2,^&,foobar] is actually returning fo^&ar, and this is later expanded to fo&ar.
This works around it. You can use any character after the first /E, that is not likely to appear in your headings. %= accesses the escape character, and a second setdos will restore it to its default. For some generic batch, you could get away with an environment variable.
setdos /E£ & echo %@subst[2,^,foobar & setdos /E^
If you don't want to use the second setdos, you could nest the command in a setlocal / endlocal.
---- Original Message ----
Sent: Sunday, 2011. February 27. 09:39
Subject: RE: [Support-t-2635] Re: @SUBST ... how replace character with
| Originally Posted by vefatica
| This one behaves rather oddly:
| v:\> echo %@subst[3,%%@char,foobar]
| foo^What happened to the rest of the string?
| It was overwritten, as you specified.
| @SUBST is an overwrite, not an insertion. What you passed to @SUBST
| was "3,%@char,foobar". So this translates to :
| Write the string "%@char" to the string "foobar", starting at
| position 3. The result is foo%@char.
@SUBST[n, string1, string2]: Substitutes string1 starting at position n in string2.
Using "xy" as the replacement string has similar result - 2 consecutive characters are replaced with "xy". Based on the above result, I'd like a more explicit explanation of "boundary conditions" (i.e., when position n is not part of the string). And I still do not see why replacing a single character in the string with the caret ^ truncates the string?