gpt4 book ai didi

batch-file - 使用批处理脚本将字母更改为对应的数字

转载 作者:行者123 更新时间:2023-12-03 16:49:40 24 4
gpt4 key购买 nike

我正在尝试创建一个批处理文件,它将更改一些输入文本并将它们更改为 a=1,b=2,c=3 等等 例如:

@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 脚本语言的关联数组来完成:

@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%

输出:

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

关于batch-file - 使用批处理脚本将字母更改为对应的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18377204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com