Set a word in a text file and replace or delete its value using Batchfile (User Input) -
i got error when run code. got textfile in c:\users\administrator\desktop\comorg , in, has sentence in there , need change value of word
like: run: the word inside textfile here enter input [r]-replace [d]-delete :
if click r
enter word want replace :
lets type "word" , if type word
enter word: the word replace
output = change value of word in sentence
here's code:
@echo off setlocal enabledelayedexpansion set /p _inputname= please enter "1" view text : if "%_inputname%"=="1" type "c:\users\administrator\desktop\comorg\sentence.txt " echo off echo off set /p _name= please enter input [a]-erase [b]-delete : if "%_inputname%"=="a" set /p _inputname= pick word want replace : if "%_name%"=="love" set /p _inputname= type word : echo %_name% batch script @echo %_name% batch script > c:\users\administrator\desktop\comorg\sentence.txt endlocal
for replacing parts of string, use set
command (see set /?
info):
set "string=the mouse eats cat" echo %string% echo %string:mouse=dog%
to replace variables, need delayed expansion:
setlocal enabledelayedexpansion set "string=the mouse eats cat" set old=cat set new=cheese echo !string:%old%=%new%!
Comments
Post a Comment