本文介绍了在文本文件中设置一个单词,并使用Batchfile(用户输入)替换或删除其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行代码时出现错误.就像我在C:\ Users \ Administrator \ Desktop \ ComOrg中得到一个文本文件一样在其中有一个句子,我需要更改该词的值

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

赞:跑:此处的文本文件中的单词输入输入[R]-替换[D]-删除:

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

如果我单击R

输入您要替换的单词:

让我说我输入单词"如果我输入单词

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

输入单词:您将替换的单词

输出=更改句子中单词的值

Output = Change the value of the word in a sentence

这是我的代码:

@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

推荐答案

要替换部分字符串,请使用set命令(有关信息,请参见set /?):

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%!

这篇关于在文本文件中设置一个单词,并使用Batchfile(用户输入)替换或删除其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:55