0

这是文件.txt

hello
hai

所以我想创建一个程序来读取这个文件。然后用下一个替换每个 ALPHABET。保持所有数字和其他符号不变。

所以 file.txt 会变成

ifmmp
ibj

当前已尝试读取每个 \n 然后读取该行中的每个字符,但是回显它们会导致它位于不同的行中,即

for /f "delims=" %%i in ('^<%path% findstr /n "^"') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:*:=!"
set "num=-1"
:loop
set /a num=num+1
call set "name2=%%line:~%num%,1%%"
if defined name2 (
rem set /a name2+=1 this statement wont work
    echo %name2%
goto :loop )

)

但是我得到的输出是

echo is off
e
l
l
o

有任何想法吗?

4

2 回答 2

0

set /a命令仅适用于数字,您可以尝试以下操作:

@echo off&setlocal
设置“阿尔法=abcdefghijklmnopqrstuvwxyza”
设置“测试=你好”

设置/数量=0
:环形
调用集“char=%%test:~%num%,1%%”
如果未定义 char goto:eof
调用集“alf1=%%alfa:*%char%=%%”
if "%char%" neq " " echo %alf1:~0,1%
设置 /a num+=1
转到:循环

..输出是:

一世
F
米
米
p
一世
b
j
于 2013-05-23T06:12:08.753 回答
0

这是一个 ROT13 批处理文件-您所描述的是 ROT1 翻译。也许这对你有用,或者给你一些想法,你可以修改它。

@echo off
:: by aacini
:: program works as a filter, that is, it read lines from keyboard (stdin) and send output to screen (stdout). "type filetext.txt|rot13.bat" or "rot13.bat < filetext.txt"
:: with d benham update

@echo off
:: simple rot-13 conversion filter program
setlocal disableDelayedExpansion
set lower=abcdefghijklmnopqrstuvwxyz
set upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
for /l %%a in (0,1,25) do (
  set /a "rot13=(%%a+13)%%26"
  setlocal enableDelayedExpansion
  for %%b in (!rot13!) do for /f "tokens=1-4" %%A in (
    "!lower:~%%a,1! !lower:~%%b,1! !upper:~%%a,1! !upper:~%%b,1!"
  ) do (
    endlocal
    set "lower%%A=%%B"
    set "upper%%C=%%D"
  )
)
for /f "delims=" %%a in ('findstr /n "^"') do (
  set "line=%%a"
  setlocal enableDelayedExpansion
  set "line=!line:*:=!"
  set output=
  if defined line (
    set /a len=0
    for /l %%b in (12,-1,0) do (
      set /a "len|=1<<%%b"
      for %%c in (!len!) do if "!line:~%%c,1!" equ "" set /a "len&=~1<<%%b"
    )
    for /l %%b in (0,1,!len!) do (
      set "char=!line:~%%b,1!"
      if defined lower!char! for /f delims^=^ eol^= %%c in ("!char!") do (
        if "!lower:%%c=%%c!" neq "!lower!" (
          set "char=!upper%%c!"
        ) else set "char=!lower%%c!"
      )
      set "output=!output!!char!"
    )
  )
  echo(!output!
  endlocal
)
于 2013-05-23T08:39:49.237 回答