简体   繁体   English

如何使用启用的扩展扩展进行转义

[英]How to escape " with enabledelayedexpansion in batch

Writing a simple script to find and replace a character in batch.my script contains " character which i want to replace it with some text like ".Please let me which escape character would help .Tried "" and ^" it did not work Script : ` 写一个简单的脚本来查找和替换批处理中的字符。我的脚本包含“我想用诸如“。之类的文本替换它的字符。请让我哪个转义字符会有所帮助。尝试过”“和^”脚本不起作用:`

    @echo off &setlocal 
    set search2="""
    set "replace2=""
    set "textfile=D:\Users\manajosh\Desktop\try-Copy.xml"
    set "newfile=D:\Users\manajosh\Desktop\Output.txt"
    (for /f "delims=" %%i in (%textfile%) do (
        set "line=%%i"
        setlocal enabledelayedexpansion
            set "line=!line:%search2%=%replace2%!"
            echo(!line!
        endlocal
    ))>"%newfile%"

pause 6

` `

try this technique: 尝试以下技术:

@echo off
set "search2=""
rem  set search2="""
set "replace2=""
set "line="quoted""
setlocal enableDelayedExpansion
 for /f "usebackq tokens=1,2 delims=§" %%a in ('"!search2!"§"!replace2!"') do echo "!line:%%~a=%%~b!"
endlocal

the thing is you need delayed expansion for line and also the search2 and replace2 - and this can be achieved with wrapping for loop. 事情是您需要延迟扩展行以及search2和replace2-这可以通过包装for循环来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM