-1

So here is the batch code I am using.

set fullstring=
set string=testago
echo %string%>x&FOR %%? IN (x) DO SET /A strlength=%%~z? - 2&del x

for /L %%a in (1,1,%strlength%) do (
    set b=%%a - 1
    set c=%%a
    set this=%string:~%%b,%%c%
    set fullstring=!fullstring!%this%
)

echo %fullstring%
pause

What this does is read back a string (string) character-by-character to another one (fullstring). I need to know how to overwrite the fullstring from the for loop.

alph
  • 19
  • 1
  • 5
  • 1
    I guess, you need to know, how `for`, `set` and [delayed expanison](https://stackoverflow.com/a/30284028/2152082) are working.. The content of your `for /L` loop doesn't make much sense. Enter `for /?` and `set /?` and read their output. – Stephan Sep 01 '18 at 15:13
  • Is that really your [MCVE]? Did you fail to show us your `SETLOCAL` command? – jwdonahue Sep 01 '18 at 18:13
  • Please read [Ask]. The answer to your question probably wouldn't help you with whatever your current problem is. You failed to state exactly what your script is doing as it is written. If it was doing what you intended, you probably wouldn't be asking any questions about it. – jwdonahue Sep 01 '18 at 18:15

1 Answers1

0
@echo off
setlocal enabledelayedexpansion

set "fullstring="
set "string=testago"

> x echo %string%

for %%? in (x) do set /a "strlength=%%~z? - 2"

del x

for /l %%a in (1,1,%strlength%) do (
    set /a "b=%%a - 1"
    call set "this=%%string:~!b!,1%%"
    set "fullstring=!fullstring!!this!"
)

echo "%fullstring%"
pause

In the for /l loop, no need for c variable so removed.

Use of call set to do a 2nd parse of the line to set this variable. b requires delayed expansion then string variable needs expanding so use of call set on string using doubled percentages achieves this.

The 2nd argument of the variable substitution is the length. Character by character will be a constant 1 for length.

Concatenating the full string will require delayed expansion or use of call set as an alternative.

michael_heath
  • 5,262
  • 2
  • 12
  • 22