使用批处理脚本将字母更改为数字形式的对应字母 [英] Use batch script to change letters into their numerical counterpart

查看:246
本文介绍了使用批处理脚本将字母更改为数字形式的对应字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个批处理文件,该文件将更改一些输入文本并将其更改为与a=1b=2c=3等对应的数字,例如:

I'm trying to create a batch file that will change some input text and change them into their number counterparts of a=1,b=2,c=3 etc for example:

@echo off

set /p text=

echo :: %text% ::
echo Is this the expected text? //user can manually typo check
pause
cls

for /f delims=: %%i in ("%text%") do ( 
[something that changes the letters into numbers & store in variable]
)

::do stuff to numbers

推荐答案

这可以使用cmd脚本语言的关联数组来完成:

this can be done with cmd script language's associative arrays:

@ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
SET "text=This is my zero text example"
SET "alfa=0abcdefghijklmnopqrstuvwxyz"
FOR /l %%x IN (1,1,26) DO SET "$!alfa:~%%x,1!=%%x"
SET /a count=0
:loop
SET "char=!text:~%count%,1!"
SET "code=!$%char%!
SET /a count+=1
IF DEFINED char SET "line=!line!%code% "&GOTO :loop
ECHO %text%
ECHO %line%


输出:


Output:

This is my zero text example
20 8 9 19  9 19  13 25  26 5 18 15  20 5 24 20  5 24 1 13 16 12 5

这篇关于使用批处理脚本将字母更改为数字形式的对应字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆