我如何在此处使用\(Backslash)并在我打印时出现它?

发布于 2025-01-25 07:19:19 字数 552 浏览 1 评论 0原文

print <<EOTEXT;

      (`-') (`-')  _<-. (`-')_            <-. (`-')  
     _(OO ) ( OO).-/   \( OO) )     .->      \(OO )_ 
,--.(_/,-.\(,------.,--./ ,--/ (`-')----. ,--./  ,-.)
\   \ / (_/ |  .---'|   \ |  | ( OO).-.  '|   `.'   |
 \   /   / (|  '--. |  . '|  |)( _) | |  ||  |'.'|  |
_ \     /_) |  .--' |  |\    |  \|  |)|  ||  |   |  |
\-'\   /    |  `---.|  | \   |   '  '-'  '|  |   |  |
    `-'     `------'`--'  `--'    `-----' `--'   `--'

EOTEXT

这是我喜欢在游戏机中出现的ASCII艺术。看起来“ \”似乎都没有出现。有什么方法可以使它出现。

print <<EOTEXT;

      (`-') (`-')  _<-. (`-')_            <-. (`-')  
     _(OO ) ( OO).-/   \( OO) )     .->      \(OO )_ 
,--.(_/,-.\(,------.,--./ ,--/ (`-')----. ,--./  ,-.)
\   \ / (_/ |  .---'|   \ |  | ( OO).-.  '|   `.'   |
 \   /   / (|  '--. |  . '|  |)( _) | |  ||  |'.'|  |
_ \     /_) |  .--' |  |\    |  \|  |)|  ||  |   |  |
\-'\   /    |  `---.|  | \   |   '  '-'  '|  |   |  |
    `-'     `------'`--'  `--'    `-----' `--'   `--'

EOTEXT

This is my ascii art that id like to show up in console. How ever it seems that " \ " doesnt show up. Is there a way that i can make it appear.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间☆小暴躁 2025-02-01 07:19:19

在双引号的字符串文字中,\是逃生序列的开始。当紧随其后的是非单词字符时,它会导致该角色产生。例如,\ |\␠分别分别为|和一个空间。当然,\\生成\,因此我们可以在double-中使用\\在其中我们想要\引用字符串文字。

there docs &lt;&lt;&lt;&lt; string string string cliterals)充当双引号的字符串文字,除非遵循&lt;&lt;的令牌是单引号。然后,弦乐产生的字符串与输入完全匹配。

因此,我们可以选择将\预备到每个特殊字符(\$@),或者我们我们可以简单地引用令牌。

print <<'EOTEXT';

      (`-') (`-')  _<-. (`-')_            <-. (`-')  
     _(OO ) ( OO).-/   \( OO) )     .->      \(OO )_ 
,--.(_/,-.\(,------.,--./ ,--/ (`-')----. ,--./  ,-.)
\   \ / (_/ |  .---'|   \ |  | ( OO).-.  '|   `.'   |
 \   /   / (|  '--. |  . '|  |)( _) | |  ||  |'.'|  |
_ \     /_) |  .--' |  |\    |  \|  |)|  ||  |   |  |
\-'\   /    |  `---.|  | \   |   '  '-'  '|  |   |  |
    `-'     `------'`--'  `--'    `-----' `--'   `--'

EOTEXT

In double-quoted string literals, \ is the start of an escape sequence. When followed by a non-word character, it causes that character to be produced. For example, \| and \␠ produce | and a space respectively. And of course, \\ produces \, so we can use \\ where we want \ in double-quote string literals.

Here docs (<< string literals) act as double-quoted string literals, unless the token that follows the << is single-quoted. Then the string produced matches the input exactly.

So we have the option of prepending \ to every special character (\, $ and @), or we can simply single-quote the token.

print <<'EOTEXT';

      (`-') (`-')  _<-. (`-')_            <-. (`-')  
     _(OO ) ( OO).-/   \( OO) )     .->      \(OO )_ 
,--.(_/,-.\(,------.,--./ ,--/ (`-')----. ,--./  ,-.)
\   \ / (_/ |  .---'|   \ |  | ( OO).-.  '|   `.'   |
 \   /   / (|  '--. |  . '|  |)( _) | |  ||  |'.'|  |
_ \     /_) |  .--' |  |\    |  \|  |)|  ||  |   |  |
\-'\   /    |  `---.|  | \   |   '  '-'  '|  |   |  |
    `-'     `------'`--'  `--'    `-----' `--'   `--'

EOTEXT
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文