@echo off
if exist SplitString.vbs del SplitString.vbs
>> SplitString.vbs Echo StringToSplit = Wscript.Arguments(0)
>> SplitString.vbs Echo CharToSplit = Wscript.Arguments(1)
>> SplitString.vbs Echo SplitArray = Split (StringToSplit, CharToSplit, -1, 1)
>> SplitString.vbs Echo For j = 0 to Ubound (SplitArray)
>> SplitString.vbs Echo Wscript.Echo SplitArray (j)
>> SplitString.vbs Echo Next
set /p String="String to split? "
set /p SplitC="Char(s) to split on? "
for /f "delims=" %%A in ('cscript //nologo SplitString.vbs "%String%" "%SplitC%"') do echo %%A
C:\>VSplit-hyphen.bat
String to split? 1-2-3-4-5-6-7-8-9
Char(s) to split on? -
1
2
3
4
5
6
7
8
9
C:\>VSplit-hyphen.bat
String to split? cat-dog-horse-bird-tree
Char(s) to split on? -
cat
dog
horse
bird
tree
C:\>VSplit-hyphen.bat
String to split? I ran - I fell - I got up again
Char(s) to split on? -
I ran
I fell
I got up again
C:\>VSplit-hyphen.bat
String to split? apple++Pear++Orange
Char(s) to split on? ++
apple
Pear
Orange
C:\>
Note: VBSCript allows splitting on a string of multiple characters
C:\>VSplit-hyphen.bat
String to split? I ran - I fell - I got up again
Char(s) to split on? - <--- There is a space here
I ran
I fell
I got up again