How to make an underscore variable "-----" with the length of the argument variable?

Microsoft Windows
Post Reply
PiotrMP006
Posts: 19
Joined: 2021-Sep-01, 10:57 am

How to make an underscore variable "-----" with the length of the argument variable?

Post by PiotrMP006 »

How to make an underscore variable "-----" with the length of the argument variable?

ex.

Code: Select all

Script Name
-----------
Please help
User avatar
Simon Sheppard
Posts: 190
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: How to make an underscore variable "-----" with the length of the argument variable?

Post by Simon Sheppard »

This question is too vague to be answerable
Hackoo
Posts: 5
Joined: 2021-Oct-17, 6:40 pm

Re: How to make an underscore variable "-----" with the length of the argument variable?

Post by Hackoo »

Code: Select all

@echo off
echo Script Name
call :MakeUnderscore 12
echo Hello World
pause
exit /b
::--------------------------
:MakeUnderscore
for /l %%i in (1,1,%1) do (
    set /p =-<nul
)
echo(
Exit /B
::--------------------------
The subroutine :MakeUnderscore uses a for loop to generate a series of underscores based on the number passed as an argument. set /p =-<nul command is used to print an underscore without a newline character.
The echo( command is then used to print a newline character.
Finally, the Exit /B command is used to exit the subroutine.
Post Reply