Ok so ive been working on a fairly complex batch file that basicly asks the user to create a text file that contains 6 (or more) lines of text. Then it takes that file and changes every instance of every letter to its respective number (for example if the first line of the text file said "programable" then the program would change all instances of the letter "a" into 1 and "b" into 2 and so on until it was all numbers. It would then read "16 18 15 7 18 1 13 1 2 12 5") and i would do that by using the following script:
set /p var=< text.txt
set var=%var:a=1%
echo.%var% >> text.txt
However the only problem with this script is that it will only change the letter a on the first line to 1, not the letter "a" in the rest of the document.
I also tried splitting the document at the beginning of the program so that when the user types the text for the first line it sends it to a separate hidden file (text1.txt) instead of just sending all of the lines of text that the user types, into one text file (text.txt)
I did so using this:
set /p line1=type the first line:
echo %line1% >> text1.txt
attrib +h text1.txt
set /p line2=type the second line:
echo %line2% >> text2.txt
attrib +h text2.txt
:: ########################################################################
:: Im not going to repeat this 6 times but hopefully you get my point
:: ########################################################################
Now the problem with splitting the lines into separate files is that it would be in-efficient and extremely time consuming to change all instances of every letter into their respective numbers, and do it for each line (or in this situation, file) that the user inputs... If it would help if i put all this in context, here is the script for my program so far, for the ":LOADING" subscript i am currently using the method i explained earlier where i split the lines into files.
Code: (Save As "stringparsing.bat")
@echo off
title BETA
cls
echo.
echo.
echo.
echo Setting Variables...
echo Loading Language Database...
:: ###################################################################################
:: CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE
:: ###################################################################################
:: An Idea i was thinking of trying was to put a subscript here that calls another
:: batch file that contains a list of the letters set as variables to their
:: respective numbers (example: SET a=1, SET b=2, SET c=3)
:: -----------------------------------------------------------------------------------
PING 1.1.1.1 -n 1 -w 3000 >NUL
goto MAIN
:MAIN
set foo=0
cls
echo.
echo.
echo.
echo.
echo ===================================
echo #################################
echo ####### Main Menu: #######
echo #################################
echo ===================================
echo.
echo.
echo 1.) Create New Language File...
echo.
echo 2.) Load Existing Lanuage File...
echo.
echo 3.) Settings...
echo ---------------------------------------------------------
SET /p CHOICE= Select a Function:
IF %CHOICE%== 1 GOTO CREATE
IF %CHOICE%== 2 GOTO LOAD
IF %CHOICE%== 3 GOTO SETTINGS
GOTO MAIN
:CREATE
cls
title Step 1
echo.
echo.
echo.
echo echo ============================================================================
echo.
set /p name= please type a name for your new language file:
echo.
echo =================================================================================
cls
echo.
echo.
echo.
echo ==============================================================
echo ##############################################################
echo #============================================================#
echo # #
echo # - After you hit enter you will be redirected #
echo # to a Live Typer. so anything you type into #
echo # it will be sent to %name%.txt. #
echo # #
echo # #
echo # - Next, select load language! #
echo # #
echo #============================================================#
echo ##############################################################
echo ==============================================================
pause
goto typer1
:typer1
cls
set /p line1= :
echo %line1% >> %name%1.txt
attrib +h %name%1.txt
cls
set /p line2= :
echo %line2% >> %name%2.txt
attrib +h %name%2.txt
cls
set /p line3= :
echo %line3% >> %name%3.txt
attrib +h %name%3.txt
cls
set /p line4= :
echo %line4% >> %name%4.txt
attrib +h %name%4.txt
cls
set /p line5= :
echo %line5% >> %name%5.txt
attrib +h %name%5.txt
cls
set /p line6= :
echo %line6% >> %name%6.txt
attrib +h %name%6.txt
cls
echo.
echo.
echo.
echo ==========================================================
echo.
(
IF EXIST %name%1.txt echo - FIRST LINE CONFIRMED.
IF EXIST %name%2.txt echo - SECOND LINE CONFIRMED.
IF EXIST %name%3.txt echo - THIRD LINE CONFIRMED.
IF EXIST %name%4.txt echo - FOURTH LINE CONFIRMED.
IF EXIST %name%5.txt echo - FIFTH LINE CONFIRMED.
IF EXIST %name%6.txt echo - SIXTH LINE CONFIRMED.
echo %name% > Language_File.txt
attrib +h Language_File.txt
set /a foo+ =1
)
echo.
echo ==========================================================
goto LOAD
:LOAD
set /a foo+ =1
IF %foo%== 2 goto loadexternal
goto LOAD23
:loadexternal
echo.
echo language file is loading now!
pause > nul
cls
set /p name=<Language_File.txt
echo.
echo.
echo Language_File Loaded!
pause >nul
goto LOAD23
:LOAD23
cls
echo.
echo.
echo.
echo.
echo.
echo Encoding Your Language File... Please Wait...
echo.
echo.
echo.
PING 1.1.1.1 -n 1 -w 3000 >NUL
:A1
set /p var=< %name%1.txt
set var=%var:a=1%
echo.%var%
echo %var% > %name%1.txt
echo.
echo.
echo.
echo "A" done.
goto B1
:B1
set /p var=< %name%1.txt
set var=%var:b=2%
echo.%var%
echo %var% > %name%1.txt
echo.
echo.
echo.
echo "B" done.
goto C1
:C1
set /p var=< %name%1.txt
set var=%var:c=3%
echo.%var%
echo %var% > %name%1.txt
echo.
echo.
echo.
echo "C" done.
goto D1
:D1
set /p var=< %name%1.txt
set var=%var:d=4%
echo %var% > %name%1.txt
echo "D" done.
goto E1
:E1
set /p var=< %name%1.txt
set var=%var:e=5%
echo %var% > %name%1.txt
echo "E" done.
goto F1
:F1
set /p var=< %name%1.txt
set var=%var:f=6%
echo %var% > %name%1.txt
echo "F" done.
pause
cls
type %name%.txt
pause >nul
goto MAIN
:END
cls
title SHUTTING DOWN...
echo.
echo.
echo.
echo Terminating service stream...
echo.
echo.
echo.
echo.
echo Done! Thank you for using this program!
ping 1.1.1.1 w -n 1 -w 6000 > NUL
Exit***
If you have a solution i would be glad to hear it because i have been searching high and low for a solution to this problem but have found nothing. Also, if any one notices any other mistakes or errors in my script then please feel free to comment!
Thanks in advance!
PS. If the last script i posted in this topic didnt come out right or it was all mixed up then just download the script from this link:
[http://home.danieljewison.operaunite.com/f/content/Documents/stringparsing.bat][1]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…