再举个栗子:- @echo off&setlocal enabledelayedexpansion
- set "str=.....(省略).....>截取字段1</a><..(省略)..><...>截取字段2</a>.....(省略)....."
-
- set "index=!str:*截取字段1</a>=!"
- set "length=!index:*>截取字段2</a>=!"
- echo !index!
- echo !length!
- call :strlen index index
- call :strlen length length
- echo !str:~-%index%,%length%!
- pause&exit /b
-
-
- :strlen <stringVarName> [retvar]
- :: 思路: 二分回溯联合查表法
- :: 说明: 所求字符串大小范围 0K ~ 8K;
- :: stringVarName ---- 存放字符串的变量名
- :: retvar ---- 接收字符长度的变量名
- setlocal enabledelayedexpansion
- set "$=!%1!#"
- set N=&for %%a in (4096 2048 1024 512 256 128 64 32 16)do if !$:~%%a!. NEQ . set/aN+=%%a&set $=!$:~%%a!
- set $=!$!fedcba9876543210&set/aN+=0x!$:~16,1!
- endlocal&If %2. neq . (set/a%2=%N%)else echo %N%
复制代码
|