不是EXCEL和数据库那种表,是我自己手写的表
手写的还要用OCR转换,你确定批处理搞得定??? 本帖最后由 slore 于 2022-9-5 16:18 编辑
@echo off&SETLOCAL ENABLEDELAYEDEXPANSION
set key_str=a b c d e f g h i j
set value_str=1 2 3 4 5 6 7 8 9 0
call :CREATE_DICT
set /p input=请输入(a-j):
call :TRANS
echo %trans_input%
pause
goto :EOF
rem =======================================
:TRANS
set trans_input=&set n=0
:NextInputChar
set c=!input:~%n%,1!
if "%c%"=="" goto :EOF
set /a n+=1
set trans_input=%trans_input%!Dict[%c%]!
goto :NextInputChar
goto :EOF
:CREATE_DICT
set /a n=0 & for %%i in (%key_str%) do ( set /a n+=1&&call set KEYS[!n!]=%%i)
set /a n=0 & for %%i in (%value_str%) do (set /a n+=1&&call set Dict[%%KEYS[!n!]%%]=%%i)
goto :EOF bjay2008xmy 发表于 2022-9-5 15:51
看起来很复杂,好像用到了数组
批处理能做,就是复杂。
随便换个, vbs, python, ruby, lua 简单的不像话。
不是要求必须用批处理弄的话,建议你看下python吧。
属于降维简化代码。 另外,如果不用动态创建 “字典”,代码应该更清楚些吧。
@echo off&SETLOCAL ENABLEDELAYEDEXPANSION
set Dict=1
set Dict=2
set Dict=3
set Dict=4
set Dict=5
set Dict=6
set Dict=7
set Dict=8
set Dict=9
set Dict=0
set /p input=请输入(a-j):
call :TRANS
echo %trans_input%
pause
goto :EOF
rem =======================================
:TRANS
set trans_input=&set n=0
:NextInputChar
set c=!input:~%n%,1!
if "%c%"=="" goto :EOF
set /a n+=1
set trans_input=%trans_input%!Dict[%c%]!
goto :NextInputChar
goto :EOF 你这就是2维表。
Dict=7
Dict=5
按这个套路加维度就行。 bjay2008xmy 发表于 2022-9-5 17:21
这么改法运行就提示ECHO处于关闭状态
要输入行列,查询字典内容,我这个就是个意思。
下面循环输出的地方要变化的。
之前是1个字符一个字符转换,
现在输入A2C3得2个字符一起找,
下面的TRANS也需要对应修改下。
直接用可能找不到匹配。
你最好像1楼一样,把处理要求,和输入例子补充完整。
bjay2008xmy 发表于 2022-9-5 19:11
我感觉这个数组就像变量一样,不用[]也可以,Dict_1=7.
Dict_!num!
本来就是。写成数组只是好看。
set Dict列出来,方便。 本帖最后由 dos时代菜鸟 于 2022-9-5 20:33 编辑
如下代码,适用 a-z ,再大的 比如 aa,ab,ac,ad,ae...等两个字母的,需要再复杂一点儿。
@echo off
setlocal ENABLEDELAYEDEXPANSION
:loop1
set str1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
SET N=0
set /p str2=请输入一段英文字母:
if "!str2!"=="" goto :error1
set "str2=!str2: =!"
echo.
echo "!str2!"
set "str3="
set n1=0
:loop2
for %%c in (!n1!) do (
if "!str2:~%%c,1!"=="" goto :end1
set found=0
for /l %%n in (1,1,26) do (
if /i"!str1:~%%n,1!"=="!str2:~%%c,1!" (
set "str3=!str3!,%%n"
set found=1
)
)
if !found! equ 0 goto :error2
)
set /a n1+=1
goto :loop2
:end1
echo !str3!
pause
goto :eof
:eorro1
echo 输入错误
pause
goto :loop1
:error2
echo 输入错误,包含非英文字母内容
pause
goto :loop1
bjay2008xmy 发表于 2022-9-5 20:56
slore的代码很有特点,就是前面的简单,把具体实现的方法都放在后面了。我只看的懂前面,可以白嫖一个查 ...
你要怎么输入双位的坐标,还有和一楼的例子,
你输入啥,输出啥。你都没说。后面不知道怎么引用表。 # 如果要返回26个英文字母的序号,这个确实很简单,方法之一,我这Python幼儿园的水平也能写出一点
import string
s = input('请输入: ')
x = y = ''
for i in s.upper():
x += i + '\t'
y += str(int(string.ascii_uppercase.index(i))+1) + '\t'
print(x)
print(y)
输入数字,返回字母
import string
t = input('请输入1-26之间的数字,空格分隔:')
a = b = ''
for i in t.split():
a += i + '\t'
b += string.ascii_uppercase + '\t'
print(a)
print(b)
页:
[1]
2