Question: Suppose I have a string "AAA BBB CCC DDD EEE FFF".

How can I split the string and retrieve the nth substring, in a batch file?

The equivalent in C# would be

```
"AAA BBB CCC DDD EEE FFF".Split()[n]

```

Answer: 
I ended up with the following:

```
set input=AAA BBB CCC DDD EEE FFF
set nth=4
for /F "tokens=%nth% delims= " %%a in ("%input%") do set nthstring=%%a
echo %nthstring%

```

With this you can parameterize the input and index. Make sure to put this code in a bat file.
or Powershell for a 0 indexed array.

```
PS C:\> "AAA BBB CCC DDD EEE FFF".Split()
AAA
BBB
CCC
DDD
EEE
FFF

PS C:\> ("AAA BBB CCC DDD EEE FFF".Split())[0]
AAA

```