转义echo命令中的所有文本

时间:2022-11-20 22:27:32

I'm making text art in a batch file is there a way escape all of the vertical bars in the echos?

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

Not using ^s the carets set the lines of text off.

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

1 个解决方案

#1


2  

Just some options. There are more, but it depends of the real needs

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

@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:||||||||||||||||||||||||||||||||||||||||||||||

#1


2  

Just some options. There are more, but it depends of the real needs

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

@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:||||||||||||||||||||||||||||||||||||||||||||||