Board logo

标题: 求助,关于字符串截取出错的问题 [打印本页]

作者: Liuzl     时间: 2010-9-3 01:01    标题: 求助,关于字符串截取出错的问题
::将一个十六进制的数转换成十进制 @echo off if "%1"=="/?" goto :explain if "%1"=="" goto :explain setlocal enabledelayedexpansion set ver=%1 set temp=!ver! set num=1 :label set temp%num%=%temp:~1% if not defined temp%num% goto :next set temp=!temp%num%! set /a num+=1 goto :label :next echo %num% if %num% GEQ 6 echo Out of data! & pause>nul & exit ::=================================================== set TEMP=!ver:0,-1! & set snum=0 & set change=1 echo %TEMP% echo %ver% echo %TEMP:~-1% ::问题在此处,%TEMP:~-1% 没法读到倒数第一位,为什么? ::=================================================== for /l %%j in (1,1,%num%) do ( ping -n 1 127.0.0.1 >nul echo !TEMP:~-1! set /p var=%%j: if "!TEMP:~-1!"=="a" set /a snum=snum+10*change & goto :else if "!TEMP:~-1!"=="b" set /a snum=snum+11*change & goto :else if "!TEMP:~-1!"=="c" set /a snum=snum+12*change & goto :else if "!TEMP:~-1!"=="d" set /a snum=snum+13*change & goto :else if "!TEMP:~-1!"=="e" set /a snum=snum+14*change & goto :else if "!TEMP:~-1!"=="f" set /a snum=snum+15*change & goto :else set /a snum=snum+!TEMP:~-1!*snum set TEMP=!TEMP:~0,-1! :else set /a change=!change!*16 echo ===========!change! echo ============!snum! ) echo %1的转换结果是%snum% pause>nul&goto :eof :explain cls&echo.&echo. echo ===================================================== echo. echo 十六进制向十进制转换 echo. echo ——writed by Liuzl echo. echo. echo 按任意键退出...... echo. echo ===================================================== pause>nul&exit ::哪位高手能帮解决,感激不尽!

作者: ZJHJ     时间: 2010-9-3 11:02
干吗要这样复杂呀? 十六进制的数转换成十进制 echo off cd.>十进制.txt setlocal EnableDelayedExpansion for /f %%a in (1.txt) do ( set s=%%a set /a s=0x!s! set /p=!s! <nul >>十进制.txt )

作者: Liuzl     时间: 2010-9-3 23:07
谢谢了,初学不是很清楚