batch multiple variables from input string

Viewed 46

I need to get variables from each symbol after input and mix them, add separates and other symbol like
input prompt: 123456789012345
output: xy 1z 32 54 76 98 10 32 54

I made this, but it had to enter symbols one by one

SET /P d1=Enter 1 digit:  
SET /P d2=Enter 2 digit:  
SET /P d3=Enter 3 digit:  
SET /P d4=Enter 4 digit:  
SET /P d5=Enter 5 digit:  
SET /P d6=Enter 6 digit:  
SET /P d7=Enter 7 digit:   
SET /P d8=Enter 8 digit:  
SET /P d9=Enter 9 digit:  
SET /P d10=Enter 10 digit:  
SET /P d11=Enter 11 digit:  
SET /P d12=Enter 12 digit:  
SET /P d13=Enter 13 digit:  
SET /P d14=Enter 14 digit:  
SET /P d15=Enter 15 digit:  
ECHO XY %d1%Z %d3%%d2% %d5%%d4% %d7%%d6% %d9%%d8% %d11%%d10% %d13%%d12% %d15%%d14% 
1 Answers

This is the way I would do it:

@echo off
setlocal

set /p "str=Enter 15 digits: "

set "out=xy %str:~0,1%z"

set "str=%str:~1%"

:nextNum
set "out=%out% %str:~1,1%%str:~0,1%"
set "str=%str:~2%"
if defined str goto nextNum

echo %out%

Example:

Enter 15 digits: 123456789012345
xy 1z 32 54 76 98 10 32 54
Related