Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Adrianvdh
- Posts: 177
- Joined: 16 May 2013 13:00
#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
#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
#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...
Thank you for your help, if you can help me

-
aGerman
- Expert
- Posts: 4743
- Joined: 22 Jan 2010 18:01
- Location: Germany
#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
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#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.