将数值转换回字母

时间:2018-08-03 07:55:59

标签: batch-file character numeric

我在这里找到了一个batch .cmd项目,它可以将字母转换为其数值:

@echo off

:start

cls

color 9a

setlocal enableDelayedExpansion

echo.

set /p text=(your message) = 

set "code=!text!"

set "chars=0abcdefghijklmnopqrstuvwxyz"

for /l %%N in (1 1 26) do for /f %%C in ("!chars:~%%N,1!") do set "code=!code:%%C=%%N !"

cls

echo.

echo (your message) = !text!

echo.

echo (numeric value) = !code!

echo.

pause

goto :start

如果我键入“我爱你”,其数值将为“ 9 12 15 22 5 25 15 21”

我想做的是扭转如果输入数字值时会出现相应字母或单词的动作。

该怎么做?

1 个答案:

答案 0 :(得分:0)

只需后退即可

@echo off
Setlocal enableDelayedExpansion
Set "chars=0abcdefghijklmnopqrstuvwxyz"
set /p code= input code 
If "!code:~-1!" neq " " set "code=!code! "
for /L %%N in (26 -1 1) do (
  for /f %%C in ("!chars:~%%N, 1!") do set "code=!code:%%N =%%C!"
)
Echo text = !code!

菲尔