求助,关于批处理字符串截取出错的问题
求助,关于字符串截取出错的问题::将一个十六进制的数转换成十进制@echooffif"%1"=="/?"goto:explainif"%1"==""goto:explai...
求助,关于字符串截取出错的问题
::将一个十六进制的数转换成十进制
@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
::哪位高手能帮解决,感激不尽! 展开
::将一个十六进制的数转换成十进制
@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
::哪位高手能帮解决,感激不尽! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询