@echo off
echo Printing repeated character
call :printStrings retVal 3 #
echo Returned String: "%retVal%"
PAUSE
:printStrings
(
setlocal EnableDelayedExpansion
set /a "Number=%~2"
rem set /a "counter=60-!Number!"
set "returnStr="
set "repeatChar=%~3"
rem echo Character to repeat: %repeatChar%
FOR /L %%G IN (1,1,!Number!) DO (
set "returnStr=%returnStr%%repeatChar%"
echo Adding character
)
)
(
endlocal
set "%~1=%returnStr%"
rem set "%~1=%repeatChar%"
exit /b
)
我需要通过调用该函数来打印x特定字符的次数,所以如果我这样做的话
call :printStrings retVal 3 #
预期的输出将是
返回的字符串:“ ###”
请帮助我的脚本不起作用。 @echo off echo打印重复的字符调用:printStrings retVal 3#echo返回的字符串:“%retVal%” PAUSE:printStrings(setlocal ...
set "returnStr=%returnStr%%repeatChar%"
将失败,因为%returnStr%和%repeatChar%的扩展已完成。