2

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
  • 3
    What's wrong with @Set /P "d=Enter a fifteen digit string: "? Then after properly validating the input you could use variable expansion to choose your wanted digits by position, e.g. @Echo XY %d:~0,1%Z %d:~2,1%%d:~1,1% %d:~4,1%%d:~3,1% %d:~6,1%%d:~5,1% %d:~8,1%%d:~7,1% %d:~10,1%%d:~9,1% %d:~12,1%%d:~11,1% %d:~14,1%%d:~13,1%. Commented Jun 23, 2022 at 17:46

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.