0
請幫助我的腳本不工作。批處理文件:函數,創建特定字符的字符串,x次數
@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 #
預計產量將
返回的字符串:「###」
_My腳本不會working_,啊哈,你在iPhone上進行測試,或者您試圖在Linux或哪一部分是不工作? – jeb 2012-03-05 09:22:49
即使「添加字符」打印了3次,返回的值也始終爲空。 – Zenellie 2012-03-05 09:27:55
http://rosettacode.org/wiki/Repeat_a_string#4DOS_Batch很有趣 – 2015-04-26 08:38:41