set ACTION_MAP=NOT_FOUND;CPY-Y;DEL-Y
set ACTION_SEARCH=%1
call set ACTION_SEARCH=%%ACTION_MAP:*%ACTION_SEARCH%-=%%
set ACTION_SEARCH=%ACTION_SEARCH:;=&rem.%
if "%ACTION_SEARCH%"=="Y" (
echo. do something here.....
) else (
echo.
echo [Error] Action, %3, not found!
exit /b 1
)
set ACTION_MAP=NOT_FOUND;CPY-Y;DEL-Y
設定mapping的項目及目標值
set ACTION_SEARCH=%1
假設由%1傳入要搜尋的字串
call set ACTION_SEARCH=%%ACTION_MAP:*%ACTION_SEARCH%-=%%
在ACTION_MAP中搜尋ACTION_SEARCH字串, 並將字串前(包含字串)皆替換為空白
set ACTION_SEARCH=%ACTION_SEARCH:;=&rem.%
將分號(;)後的字串(含分號)亦替換成空白, 就可以利用ACTION_SEARCH的結果來判斷是否找到要搜尋的字串了
沒有留言:
張貼留言