1、判断x 变量是否在foo变量中
echo "%foo%" | findstr /C:"%x%"
** 2、 函数写法** 参考: 函数定义和用法
@echo off
set "aStr=Expect no changed, even if used in function"
set "var1=Expect changed"
echo.aStr before: %aStr%
echo.var1 before: %var1%
call:myGetFunc var1
echo.aStr after : %aStr%
echo.var1 after : %var1%
echo.&pause&goto:eof
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:myGetFunc - passing a variable by reference
SETLOCAL
set "aStr=DosTips"
( ENDLOCAL
set "%~1=%aStr%"
)
goto:eof
:myGetFunc2 - passing a variable by reference
SETLOCAL
set "aStr=DosTips"
ENDLOCAL&set "%~1=%aStr%" &rem THIS ALSO WORKS FINE
goto:eof
一个标准函数定义
:myFunctionName -- function description here
:: -- %~1: argument description here
SETLOCAL
REM.--function body here
set LocalVar1=...
set LocalVar2=...
(ENDLOCAL & REM -- RETURN VALUES
IF "%~1" NEQ "" SET %~1=%LocalVar1%
IF "%~2" NEQ "" SET %~2=%LocalVar2%
)
GOTO:EOF