Showing characters in user input?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Showing characters in user input?

#1 Post by Adrianvdh » 14 Jun 2013 08:37

Hello everyone...

I need some help...

If I were to add a user input variable and the user enters "3"

how would I make a function to echo the character "-" 3 times

Input:
3
Output:
---

Thanks for all your help and your time :)

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Showing characters in user input?

#2 Post by Squashman » 14 Jun 2013 09:51

Open up a cmd promt and type: FOR /?
Read the section about using the /L option.

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Showing characters in user input?

#3 Post by Adrianvdh » 14 Jun 2013 11:05

Hi, sorry I am struggling a lot here with the "for /l" command :(

This is what I have so far...

Code: Select all

for /l %a in (1,1,52) do echo -


Thank you for your help, if you can help me :)

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Showing characters in user input?

#4 Post by aGerman » 14 Jun 2013 11:35

FOR /L is only midway. The second half is how you would print it in one line.
Imho two possibilities.

1st create a variable

Code: Select all

set /p "n=Number: "
setlocal EnableDelayedExpansion
set "hyphens="
for /l %%i in (1 1 %n%) do set "hyphens=!hyphens!-"
endlocal &set "hyphens=%hyphens%"
echo %hyphens%



2nd use the SET /P trick to display text without linebreak.

Code: Select all

set /p "n=Number: "
for /l %%i in (1 1 %n%) do <nul set /p "=-"
echo(

Regards
aGerman

Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Re: Showing characters in user input?

#5 Post by Adrianvdh » 14 Jun 2013 12:25

Thanks a lot "aGerman" you are very helpful :)

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Showing characters in user input?

#6 Post by Squashman » 14 Jun 2013 18:45

aGerman wrote:FOR /L is only midway. The second half is how you would print it in one line.

I guess your are right. I shouldn't have assumed the user knew how to use the set command. Figured they knew how from all the other scripts that have been given to them.

Post Reply