Oh the 10K and 20K and 100K will want to call this a duplicate.. but it's not.
The reason for this is merely:
Use Array Variable, "arr" Use a counting variable, "x", or whatever
Compare array index:
Does arr == arr ? (but with dynamic counting vars)
You can't do that with -- For /L (0,1, length), because set x+=1 and also the variable !arr! can't, or I don't know how, work together as both variables.
I've tried using %x% and !x! and setlocal and not using setlocal...
I can't seem to get the correct combination of variable syntax.
In other words: arr[x] == arr[x+1] ? in a loop comparison
Set "inName=%~1" Set arrCount=0 Set count=0 Set arr =  :: Do some work :: Some code delted for clarity of problem at hand :: populate the arr (array) :loop call set "char=%%inName:~%count%,1%%" If defined char ( echo %count%[%char%] Set arr[%count%]=%char% Set /a arrCount+=1 Set /a count+=1 Set trimName=%trimName%%char% goto :loop ) Set x=0 setlocal enableDelayedExpansion REM fails of tried variable variations :: echo array is %arrCount% in length :: call echo X is %x% at %%arr[%x%]%% :: call echo letter: %%arr[%x%]%% :: define: !arr[%x%]! !arr[!!x!!]! !!arr[!x!]!! and other variations :SymLoop if defined !arr[%x%]! ( echo X---: !arr[%x%]! CALL :increment RESULT x GOTO :SymLoop ) :: Different methods of resetting x to zero. Both fail set /a x=0 CALL :reset_one RESULT x :: For loop, using counter for /L %%F in (0,1,%arrCount%) do ( echo !arr[%%F]! and !arr[%x%]! vs !arr[!%x%!]! -- x is !x! call Set /A x+=1 REM CALL :increment RESULT x ) endlocal EXIT :increment SET /A countArray+=1 SET /A x+=1 :reset_one SET /A x=0
The input to this batch file is: some__name
Loops I've tried as you an see:
I have tried executing a simulated loop, via GOTO:SymLoop
Also, tried reading, echoing, array, via If defined !arr[%x%]!
RESULTS: I can get x to increment, but the combination of "arr" and "x" no
s and s vs 0 -- x is 0 o and s vs 0 -- x is 1 m and s vs 0 -- x is 2 e and s vs 0 -- x is 3 _ and s vs 0 -- x is 4 _ and s vs 0 -- x is 5 n and s vs 0 -- x is 6 a and s vs 0 -- x is 7 m and s vs 0 -- x is 8 e and s vs 0 -- x is 9 and s vs 0 -- x is 10
The input: "some__name", will be compared with passing "some_name" into the batch file mybatch.bat >C:....>mybatch some__name
basically I populate the array [s][o][m]...
I want to ask: index 0 match index 1?
Later I will ask, is index-n of char "" and also index-n+1 of char "" ?
edit: I've come across a statement, comment, and found this. I'm not a Windows engineer. I use my skills as a programmer to get by in batch file creation. So I don't fully understand the deeper issues of my logic. From what I've read in the web "call echo" is a layer of expansion? So it works as if "setlocal enabledelaytedexpansion..." ? Somehow the second line "call echo" works, which leads me to believe that arr is indeed defined.
Set x=0 ::fails echo Array: arr is %%arr[%x%]%% ::works Call echo Array: arr is %%arr[%x%]%%
From Comment Suggestion:
if defined arr[%x%] ( could work. Read if /?: the correct syntax is IF DEFINED variable command (here variable is supposed to be a variable name and not expanded !variable!)
As for the rest of the code it was this above-comment that lead me to the full completion of the batch file. I was able to fix the :SymLoop and read the array correctly.
:SymLoop Call Set "ArrVar=%%arr[%x%]%%" If defined ArrVar ( Call echo X---: !arr[%x%]! Set /A x+=1 GOTO :SymLoop )