對不起。我不喜歡這種類型的代碼。在我個人看來,這是很清楚的來管理這些值作爲陣列這樣:
rem Prepare the array of two-digits values for each 3-letters month names:
for %%a in ("Jan=01" "Feb=02" "Mar=03" "Apr=04" "May=05" "Jun=06" "Jul=07" "Aug=08" "Sep=09" "Oct=10" "Nov=11" "Dec=12") do (
set month%%~a
)
rem Previous code is equivalent to these 12 lines:
rem set monthJan=01
rem set monthFeb=02
. . . .
rem set monthDec=12
rem This way, the result is immediately accessible:
SET v=May
CALL SET v=%%month%v%%%
rem Or in the clearer way using Delayed Expansion:
SET v=!month%v%!
monthXXX
是值的12種不同的3字母月份名稱的陣列。
SET v=May
將索引的值設置爲元素數組。
SET v=!month%v%!
首先擴展到SET v=!monthMay!
(正常擴展),然後到SET v=05
(延遲擴展)。
我解釋我喜歡這個符號與每一個細節中看到這些訊息的原因:
Arrays, linked lists and other data structures in cmd.exe (batch) script
DIR output into BAT array?
我道歉,如果有人認爲這個答案是題外話...
Antonio
您沒有使用'設置/了'任何地方 – Joey
順便說一句。使用'set v =%v:〜0.2%'會更容易,因爲這裏不需要'&REM'技巧 – jeb