1 頁 (共 1 頁)

[batch] 取字串

發表於 : 2022-02-07, 13:40
Lexaul
參考資料:http://jdev.tw/blog/6037/batch1-windows ... t-variable

取子字串:用 ~ 和 ,
格式:環境變數:~開始位置[,長度]
開始位置由 0 起算 (Zero-based)
開始位置若為負值,表示由結尾向前
功能:環境變數的子字串操作

rem是註解的意思

代碼: 選擇全部

rem 範例:13時35分8秒20
echo %time%
13:35:08.20
rem 取末兩碼
echo %time:~-2%
20
rem 取出時、分、秒
set hh=%time:~0,2%
set mm=%time:~3,2%
set ss=%time:~6,2%
echo %hh%,%mm%,%ss%
13,35,08