stringparsing.bat 问题的第二部分
好的,我的 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
Ok so everything's working with my stringparsing.bat program, i can successfully create, encode, and display the text files. However now the problem arises that it will not decode the the text file after encoding it. Say if the encoded text file contains:
20 18 1 9 14 19
When i decode it using this script:
@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
I get:
t 1h a i 1d 1i
Because when the program decodes the letter r (which is 18) it mistakes the 8 in 18 for the letter h and therefore puts 1h... so is there a way to make it a specific search and replace? (similar to if your typing a path to a file with spaces in it,you would put quotes around the path and file name) If so what would the format be?
EDIT Heres the current script for the stringparsing.bat program:
@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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊哈,你有问题了。你就会看到原因。
18被替换为
之前正确的行可以替换它的行。
如果你不能解决问题,那么就没有希望了。 :-)
Aha, you got the problem. And you see the cause.
The 18 is replaced by the line
before the correct line can replace it
If you can't solve the problem, then there's no room for hope. :-)