You are not logged in.

#1 25 Jun 2016 05:14

Rebelle404
Member
Registered: 25 Jun 2016
Posts: 2

Batch file - prompt user to Enter Two characters

Hello , I'm new here !
I'd like to ask about something if its possible to do with batching !

I Wanna let the user enter Two characters and the batch file echo them each one in line !

Lemme explain :

@echo off
Set /p AZ=">"

Let's say that the user entered EA
I want them to be printed like this
E
A
I dunno if this is possible !
Also I wanna know if i can let the user enter characters only ! Like we can let them enter numbers only !
Any tip ??
Thanks

Offline

#2 25 Jun 2016 12:24

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Re: Batch file - prompt user to Enter Two characters

You can use this http://stackoverflow.com/questions/1566 … a-variable if the input is only two letters

SET var=%var:~0,2%
SET var2=%var:~1,-2%
Echo %var%
Echo %var2%

This should work

Offline

#3 28 Jun 2016 01:55

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Batch file - prompt user to Enter Two characters

There is a simple fix for testing, Batcher. You may be surprised at the result.

@echo off
set "var=EA"
SET var=%var:~0,2%
SET var2=%var:~1,-2%
Echo "%var%"
Echo "%var2%"

Offline

#4 28 Jun 2016 01:58

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Batch file - prompt user to Enter Two characters

Rebelle404 wrote:
@echo off
Set /p AZ=">"

Let's say that the user entered EA
I want them to be printed like this
E
A

Batcher gave you a clue with the syntax, but his numbers are wrong.

Rebelle404 wrote:

Also I wanna know if i can let the user enter characters only ! Like we can let them enter numbers only !

You can't make them enter numbers only, or characters only, but you can check the result after they press enter and ask them to re-enter the details again if it is wrong.

Last edited by foxidrive (28 Jun 2016 01:59)

Offline

#5 01 Jul 2016 22:32

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Batch file - prompt user to Enter Two characters

If you're only taking two alphanumeric characters as input, couldn't you just have two choice commands?

(I'm not saying it would be easy, but it's certainly possible as long as choice exists.)

Offline

#6 09 Jul 2016 00:08

sambul35
Member
Registered: 29 Feb 2016
Posts: 18

Re: Batch file - prompt user to Enter Two characters

Rebelle404 wrote:

Hello , I'm new here !

It makes sense to rename your thread to something more revealing, like: "Entering 2 characters in a batch." smile

Offline

#7 11 Jul 2016 15:42

Rebelle404
Member
Registered: 25 Jun 2016
Posts: 2

Re: Batch file - prompt user to Enter Two characters

Thanks thanks !

im done with this ...

Offline

Board footer

Powered by