转义echo命令中的所有文本

时间:2014-02-10 19:34:53

标签: batch-file

我在批处理文件中制作文本艺术是否有办法逃避回声中的所有垂直条?

不使用^ s插入符号设置文本行。

1 个答案:

答案 0 :(得分:2)

只是一些选择。还有更多,但这取决于真正的需求

@echo off

    :: Using delayed expansion
    setlocal enabledelayedexpansion
    set "x=|| this is delayed expansion test           ||"
    echo(!x!
    echo(
    endlocal

    :: Using escaping
    setlocal disabledelayedexpansion
    set "x=|| this is escaping test                    ||"
    echo(%x:|=^|%
    echo(
    endlocal

    :: Reading the data from the current file
    for /f "delims=: tokens=1,*" %%x in ('findstr /r /c:"^:::1:" "%~f0"') do echo(%%y
    for /f "delims=: tokens=1,*" %%x in ('findstr /r /c:"^:::2:" "%~f0"') do echo(%%y

    exit /b

:::1:||||||||||||||||||||||||||||||||||||||||||||||
:::1:||                                          ||
:::1:|| this is a test                           ||
:::1:||                                          ||
:::1:||||||||||||||||||||||||||||||||||||||||||||||

:::2:||||||||||||||||||||||||||||||||||||||||||||||
:::2:||                                          ||
:::2:|| this is another test                     ||
:::2:||                                          ||
:::2:||||||||||||||||||||||||||||||||||||||||||||||