::hello bath
@echo off
setlocal enabledelayedexpansion
:main
set var=123
if %var% lss 130 echo %var% ^< 130
set count=1
for /l %%i in (0,1,3) do (
set /a count+=%%i
echo !count!
)
call :iscontained jjjkkjj kk
if %errorlevel% == 10 (
echo no contained
) else (
echo contained
)
set a=12
set b=11
call :cmpstr %a% %b%
echo %errorlevel%
set a=123456
call :strlen %a%
echo %errorlevel%
set a=123456
set b=345
call :strstr %a% %b%
echo locate = %errorlevel%
pause
::-------------------------------判断包含-------------------------------------
goto :eof
:iscontained
set source=%1
set str=%2
set tmp=!source:%str%= !
if "%tmp%"=="%source%" (
exit /b 10
) else (
exit /b 11
)
::------------------------------字符串比较--------------------------------------
goto :eof
:cmpstr
if %1 == %2 (
exit /b 0
) else if %1 lss %2 (
exit /b -1
) else if %1 gtr %2 (
exit /b 1
)
::-----------------------------字符串长度---------------------------------------
::最多可以检测长度为1024的字符串,传入包含空格字符串使用双引号包含
goto :eof
:strlen
set source=%1
set count=0
for /l %%i in (0,1,7) do (
set tmp=!source:~%%i!
if defined tmp (
set /a count+=1
) else (
goto :strlen_end
)
)
:strlen_end
exit /b %count%
::---------------------------定位子字符串-----------------------------------------
goto :eof
:strstr
call :strlen %2
set mtch=%errorlevel%
call :iscontained %1 %2
if %errorlevel% == 10 (
exit /b -1
) else (
set mstr1=%1
set mstr2=%2
set index=0
for /l %%i in (0,1,8) do (
set m1=!mstr1:~%%i,%mtch%!
if !m1! == !mstr2! (
set index=%%i
goto :strstr_end
)
)
)
:strstr_end
exit /b %index%
::--------------------------------------------------------------------
::定位字符串
::比较 *
::复制 set a=%b%
::包含判断
::链接 %var1%%var2%
@echo off
setlocal enabledelayedexpansion
:main
set var=123
if %var% lss 130 echo %var% ^< 130
set count=1
for /l %%i in (0,1,3) do (
set /a count+=%%i
echo !count!
)
call :iscontained jjjkkjj kk
if %errorlevel% == 10 (
echo no contained
) else (
echo contained
)
set a=12
set b=11
call :cmpstr %a% %b%
echo %errorlevel%
set a=123456
call :strlen %a%
echo %errorlevel%
set a=123456
set b=345
call :strstr %a% %b%
echo locate = %errorlevel%
pause
::-------------------------------判断包含-------------------------------------
goto :eof
:iscontained
set source=%1
set str=%2
set tmp=!source:%str%= !
if "%tmp%"=="%source%" (
exit /b 10
) else (
exit /b 11
)
::------------------------------字符串比较--------------------------------------
goto :eof
:cmpstr
if %1 == %2 (
exit /b 0
) else if %1 lss %2 (
exit /b -1
) else if %1 gtr %2 (
exit /b 1
)
::-----------------------------字符串长度---------------------------------------
::最多可以检测长度为1024的字符串,传入包含空格字符串使用双引号包含
goto :eof
:strlen
set source=%1
set count=0
for /l %%i in (0,1,7) do (
set tmp=!source:~%%i!
if defined tmp (
set /a count+=1
) else (
goto :strlen_end
)
)
:strlen_end
exit /b %count%
::---------------------------定位子字符串-----------------------------------------
goto :eof
:strstr
call :strlen %2
set mtch=%errorlevel%
call :iscontained %1 %2
if %errorlevel% == 10 (
exit /b -1
) else (
set mstr1=%1
set mstr2=%2
set index=0
for /l %%i in (0,1,8) do (
set m1=!mstr1:~%%i,%mtch%!
if !m1! == !mstr2! (
set index=%%i
goto :strstr_end
)
)
)
:strstr_end
exit /b %index%
::--------------------------------------------------------------------
::定位字符串
::比较 *
::复制 set a=%b%
::包含判断
::链接 %var1%%var2%