As Mofi already noted, a simple for
will do the trick. Add a counter to build up a variable for every “word” (array). Whether they are real words or numbers doesn’t matter, but some special chars will generate errors, like &
, |
or just being ignored, like %
, !
).
@echo off
setlocal enabledelayedexpansion
set count=0
set "string=some substrings with variable lengths separated by space"
for %%a in (%string%) do (
set /a count+=1
set substring[!count!]=%%a
)
set substring[
1
solved Split string with variable length in Windows Batch