Page 1 of 1

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

Posted: 2023-Dec-15, 2:56 pm
by PiotrMP006
How to make an underscore variable "-----" with the length of the argument variable?

ex.

Code: Select all

Script Name
-----------
Please help

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

Posted: 2023-Dec-15, 11:07 pm
by Simon Sheppard
This question is too vague to be answerable

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

Posted: 2024-Jan-01, 12:27 pm
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.