stringparsing.bat问题的第二部分

时间:2010-12-07 15:46:53

标签: windows variables batch-file

好的,所以一切都在使用我的 stringparsing.bat 程序,我可以成功创建,编码和显示文本文件。但是现在出现的问题是它在编码后不会对文本文件进行解码。假设编码的文本文件包含:

20 18 1 9 14 19

当我使用此脚本解码时:

@echo off
cls
echo.
echo.
echo.
echo.
echo.
echo        Decoding Your Language File... Please Wait... 
echo.
echo.
echo.

for /f "delims=" %%i in (!name1!.txt) do ( 
set var1=%%i 
set var1=!var1:1 =a ! 
set var1=!var1:2 =b ! 
set var1=!var1:3 =c ! 
set var1=!var1:4 =d ! 
set var1=!var1:5 =e ! 
set var1=!var1:6 =f ! 
set var1=!var1:7 =g ! 
set var1=!var1:8 =h ! 
set var1=!var1:9 =i ! 
set var1=!var1:10 =j ! 
set var1=!var1:11 =k ! 
set var1=!var1:12 =l ! 
set var1=!var1:13 =m ! 
set var1=!var1:14 =n ! 
set var1=!var1:15 =o ! 
set var1=!var1:16 =p ! 
set var1=!var1:17 =q ! 
set var1=!var1:18 =r ! 
set var1=!var1:19 =s ! 
set var1=!var1:20 =t ! 
set var1=!var1:21 =u ! 
set var1=!var1:22 =v ! 
set var1=!var1:23 =w ! 
set var1=!var1:24 =x ! 
set var1=!var1:25 =y ! 
set var1=!var:26 =z !
set var1=!var1:27 =. !
set var1=!var1:28 =, ! 
echo        Verifying Content...

) 

echo %var1% > %name1%.txt
echo Decoding Complete!

TIMEOUT /t 1 /nobreak > nul

我明白了:

t 1h a i 1d 1i

因为当程序对字母 r (即18)进行解码时,它会错误地将18中的8作为字母h,因此将 1h ...所以是一种使其成为特定搜索和替换的方法? (类似于如果你输入一个包含空格的文件的路径,你会在路径和文件名周围加上引号)如果是这样的格式是什么?

编辑下面是 stringparsing.bat 程序的当前脚本:

@echo off
setlocal enabledelayedexpansion 
title BETA
cls
cd /d F:\script\st
echo.
echo.
echo.
echo      Setting Variables...
echo      Loading Language Database...

set beepset=true

:: ###################################################################################
::    CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE
:: ###################################################################################




TIMEOUT /t 5 /nobreak > nul

goto MAIN

:MAIN
cls
IF %beepset%==true echo 
echo =================================================================================
echo.
echo          Please type a name for your new language file:

echo =================================================================================
set /p name=
cls
echo.
echo.
echo.
echo        ==============================================================
echo        ##############################################################
echo        #============================================================#
echo        #                                                            #
echo        # - Create the file you would like to encode.                #
echo        #                                                            #
echo        ##############################################################
echo        #                                                            #
echo        # - How many lines of text will your file have?              #
echo        #                                                            #
echo        #============================================================#
echo        ##############################################################
echo        ==============================================================




set /p linecount= 
cls
set foo=0
set linenumber=0

:lineset
set /a linenumber=linenumber+=1
set /p line1=%linenumber%
echo. >> %name%.txt
echo %line1% >> %name%.txt
set /a foo=foo+1
IF %foo%==%linecount% goto MAIN123
goto lineset


:ENCODE
title Step 2
cls
echo.
echo.
echo.
echo.      =================================================================================
echo.
echo          Please type a name of the File you want to Encode:
echo.
echo.         =================================================================================
set /p name2=

echo.
echo.
echo.
echo.
echo.
echo        Encoding Your Language File... Please Wait... 
echo.
echo.
echo.

for /f "delims=" %%i in (!name2!.txt) do ( 
set var=%%i 
set var=!var:a=1 ! 
set var=!var:b=2 ! 
set var=!var:c=3 ! 
set var=!var:d=4 ! 
set var=!var:e=5 ! 
set var=!var:f=6 ! 
set var=!var:g=7 ! 
set var=!var:h=8 ! 
set var=!var:i=9 ! 
set var=!var:j=10 ! 
set var=!var:k=11 ! 
set var=!var:l=12 ! 
set var=!var:m=13 ! 
set var=!var:n=14 ! 
set var=!var:o=15 ! 
set var=!var:p=16 ! 
set var=!var:q=17 ! 
set var=!var:r=18 ! 
set var=!var:s=19 ! 
set var=!var:t=20 ! 
set var=!var:u=21 ! 
set var=!var:v=22 ! 
set var=!var:w=23 ! 
set var=!var:x=24 ! 
set var=!var:y=25 ! 
set var=!var:z=26 ! 
set var=!var:.=27 !
echo        Verifying Content...

) 

echo %var% > %name2%.txt
echo Encoding Complete!

TIMEOUT /t 1 /nobreak > nul

goto MAIN123

:DECODE
title Decode...
echo.
echo.
echo.
echo         =================================================================================
echo.
echo          Please type a name of the File you want to decode:
echo.
echo         =================================================================================
set /p name1=

:decoderscript
cls
echo.
echo.
echo.
echo.
echo.
echo        Decoding Your Language File... Please Wait... 
echo.
echo.
echo.

for /f "delims=" %%i in (!name1!.txt) do ( 
set var1=%%i 
set var1=!var1:1 =a ! 
set var1=!var1:2 =b ! 
set var1=!var1:3 =c ! 
set var1=!var1:4 =d ! 
set var1=!var1:5 =e ! 
set var1=!var1:6 =f ! 
set var1=!var1:7 =g ! 
set var1=!var1:8 =h ! 
set var1=!var1:9 =i ! 
set var1=!var1:10 =j ! 
set var1=!var1:11 =k ! 
set var1=!var1:12 =l ! 
set var1=!var1:13 =m ! 
set var1=!var1:14 =n ! 
set var1=!var1:15 =o ! 
set var1=!var1:16 =p ! 
set var1=!var1:17 =q ! 
set var1=!var1:18 =r ! 
set var1=!var1:19 =s ! 
set var1=!var1:20 =t ! 
set var1=!var1:21 =u ! 
set var1=!var1:22 =v ! 
set var1=!var1:23 =w ! 
set var1=!var1:24 =x ! 
set var1=!var1:25 =y ! 
set var1=!var:26 =z !
set var1=!var1:27 =. !
set var1=!var1:28 =, ! 
echo        Verifying Content...

) 

echo %var1% > %name1%.txt
echo Decoding Complete!

TIMEOUT /t 1 /nobreak > nul

goto MAIN123


:DISPLAY
cls
echo.
echo.
echo.
echo        Please type the name of the file you want to display:
set /p displayfile= 
type %displayfile%.txt
echo.
echo hit enter to go to Main Menu...
pause > nul
goto MAIN123

:END
cls
title SHUTTING DOWN...
echo.
echo.
echo.
echo            Terminating service stream...
echo.
echo.
echo.
echo.
echo            Done! Thank you for using this program!
TIMEOUT /t 2 /nobreak > nul





::(%xx%) -1  I/O Stream= "SHELL.dll" 
:: IF EXIST [&1[Parser_2009]] exit

Exit

1 个答案:

答案 0 :(得分:0)