0

I got an error when i run my code. Its like i got a textfile in C:\Users\Administrator\Desktop\ComOrg and in, it has a sentence in there and i need to change the value of that word

Like: Run: The word inside the textfile here Enter an input [R]-Replace [D]-Delete :

if i click R

Enter the word that you want to replace :

lets say i type "Word" and if i type the word

Enter the word: the word the you will replace

Output = Change the value of the word in a sentence

Here's my code:

@echo off 
setlocal enabledelayedexpansion

SET /P _inputname= Please enter "1" to view the text : 
    if "%_inputname%"=="1" type "C:\Users\Administrator\Desktop\ComOrg\Sentence.txt "
echo off

echo off
SET /P _name= Please enter an Input [A]-ERASE [B]-DELETE : 

    IF "%_inputname%"=="A" SET /P _inputname= Pick a word the you want to replace : 
        IF  "%_name%"=="love" SET /P _inputname= Type the word : 
            echo I %_name% batch script 
                @echo I %_name% batch script > C:\Users\Administrator\Desktop\ComOrg\Sentence.txt 


endlocal
showdev
  • 28,454
  • 37
  • 55
  • 73
  • Welcome to Stackoverflow it's hard to answer if you don't post the code! Have a look here https://stackoverflow.com/help/mcve to see how to create an example! – G M Jul 25 '17 at 14:04

1 Answers1

0

for replacing parts of the string, use the set command (see set /? for info):

set "string=The mouse eats the cat"
echo %string%
echo %string:mouse=dog%

To replace with variables, you need delayed expansion:

setlocal enabledelayedexpansion
set "string=The mouse eats the cat"
set old=cat
set new=cheese
echo !string:%old%=%new%!
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Yes. Thank you for the code. but i already used that code. I just could not do the user input on how to replace the word in a text file. – Pedro Juan Jul 26 '17 at 07:47
  • Can you do me for user input in replacing a word in a text file? – Pedro Juan Jul 26 '17 at 07:49
  • to get user input, use `set /p`. For search/replace in a textfile, see the articles below "Related" at the right side. The [first one] seems to fit perfectly. – Stephan Jul 26 '17 at 08:04
  • Yes i use it already. But i think my code has a problem. Can you do me a code? I'll show you mine and i don't know what's my error – Pedro Juan Jul 26 '17 at 08:39
  • run it without `echo off`, so it shows you exactly what it does and where it fails. – Stephan Jul 26 '17 at 08:42