stringparsing.bat 问题的第二部分

发布于 2024-10-06 07:51:57 字数 6495 浏览 0 评论 0原文

好的,我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独﹏钓一江月 2024-10-13 07:51:57

我得到:

t 1h ai 1d 1i

因为当程序解码时
字母 r (即 18)它错误
18 中的 8 代表字母 h,因此
放 1h...那么有没有办法使
它是特定的搜索和替换吗?
(类似于如果您输入一个路径
文件中包含空格,您可以输入
路径和文件名用引号引起来)
如果是的话,格式是什么?

啊哈,你有问题了。你就会看到原因。
18被替换为

set var1=!var1:8 =h !

之前正确的行可以替换它的行。

set var1=!var1:18 =r !

如果你不能解决问题,那么就没有希望了。 :-)

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?

Aha, you got the problem. And you see the cause.
The 18 is replaced by the line

set var1=!var1:8 =h !

before the correct line can replace it

set var1=!var1:18 =r !

If you can't solve the problem, then there's no room for hope. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文