如何在 DOS 批处理脚本中将字符串转换为十六进制? 例如,将“abcd”转换为“61626364”。 因为,'a' 是 0x61...
我一天试图从网络上寻找解决方案,但找不到答案。
最佳答案
@echo off
setlocal EnableDelayedExpansion
rem Store the string in chr.tmp file
set /P "=%~1" < NUL > chr.tmp
rem Create zero.tmp file with the same number of Ascii zero characters
for %%a in (chr.tmp) do fsutil file createnew zero.tmp %%~Za > NUL
rem Compare both files with FC /B and get the differences
set "hex="
for /F "skip=1 tokens=2" %%a in ('fc /B chr.tmp zero.tmp') do set "hex=!hex!%%a"
del chr.tmp zero.tmp
echo %hex%
输出示例:
C:\> test.bat abcd
61626364
关于string - DOS批处理脚本转换字符串2十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35077030/