How do i split a string dynamically inside LOOP
I Want split a string dynamically inside LOOP,But the code below not working perfectly , it look simple but it really confusing me what actually make my coding not working perfectly, maybe another methods can it be done ?
*Extra question,How to get string lenght in single loop.
sample.bat:
@echo off & setlocal EnableDelayedExpansion
:: Configuration
set "Num_1= 123"
set "Num_2= 45"
set "Num_3= 6789"
::set "Num_4= 4343321345677"
::set "Num_5= 98987675567543213"
::set "Num_6= 6766578987765544339"
::set "char1= anf,ki"
::set "char2= aewr(677)ni"
:: Get length
:length
if not "!Num_1:~%len%!"=="" set /A len+=1 & goto length
set /A L_Num_1=%len% - 1
set len=0
:length2
if not "!Num_2:~%len%!"=="" set /A len+=1 & goto length2
set /A L_Num_2=%len% - 1
set len=0
:length3
if not "!Num_3:~%len%!"=="" set /A len+=1 & goto length3
set /A L_Num_3=%len% - 1
Set Count="
:: Split
set "cha=1"
for /l %%n in (1,1,3) do (
Set Count="
for /l %%o in (!L_Num_%cha%!,-1,0) do (
Set /a "cha=cha + 1 | 1 "
Set /a "Count+=1"
set "SNum(%%n)_!Count!=!Num_%%n:~%%o,1!"
)
)
set SNum
pause
Current output
SNum(1)_7=3
SNum(1)_8=2
SNum(1)_9=1
SNum(1)_10=
SNum(2)_2=5
SNum(2)_3=4
SNum(2)_4=
SNum(3)_1=8
SNum(3)_2=7
SNum(3)_3=6
SNum(3)_4=
Output what i need
(from Variable Num_1 )
SNum(1)_1=3
SNum(1)_2=2
SNum(1)_3=1
(from Variable Num_2 )
SNum(2)_1=5
SNum(2)_2=4
(from Variable Num_3 )
SNum(3)_1=9
SNum(3)_2=8
SNum(3)_3=7
SNum(3)_4=6
Split each variable/string from backwards and create new array start from 1. i know it can be done by manually split string from variable one by one ,but at my situation i have split more dynamically because not only three string from variable i have to split,sometimes it have more than 10 variable.