可以支持多参数了
len函数为两个参数,- @echo off
-
- ::定义函数
- set "d-h=setlocal enabledelayedexpansion&set/a dx=#a#&set xs=0123456789abcdef&(for /l %%z in (1,1,4) do set /a x%%z=dx%%16,dx=dx/16)&(for /f "tokens=1-4" %%1 in ("!x1! !x2! !x3! !x4!") do set hx=!xs:~%%4,1!!xs:~%%3,1!&(if !hx!==00 set hx=)&(for %%z in ("!hx!!xs:~%%2,1!!xs:~%%1,1!") do endlocal&set #a#=%%~z))"
- ::10进制转为16进制的函数,调用方法:%d-h:#a#=变量名%
-
- set "len=for /f "tokens=1-3" %%1 in ("#a#") do setlocal enabledelayedexpansion&(if defined %%2 (set /a z=8180,x=0&(for /l %%a in (1,1,14) do set/a "y=(z-x)/2+x"&(for %%b in (!y!) do if "!%%2:~%%b,1!" equ "" (set/a z=y) else (set/a x=y)))) else (set z=0))&(for %%z in ("!z!") do endlocal&set %%1=%%~z)"
- ::取字符串长度函数,调用方法:%len:#a#=结果变量名 字符串变量名%
- setlocal enabledelayedexpansion
-
- for /l %%a in (1,7,1024) do (
- set abc=%%a
-
- (%len:#a#=slen abc%)
- (%d-h:#a#=abc%)
- (%len:#a#=dlen abc%)
- rem 函数调用
-
- echo %%a转成16进制为:!abc! 转换前字符数:!slen! 转换后字符数:!dlen!
- )
- pause
复制代码
[ 本帖最后由 netbenton 于 2009-9-22 13:10 编辑 ] |