在消息中格式化文本

发布于 2025-02-06 04:09:01 字数 1127 浏览 1 评论 0原文

我们已经很久没有说话了。

面对将文本格式化的问题。要求该消息以几行显示,左侧有空格。

下面给出了测试SRIPT。没有选项给出所需的结果。左侧的所有空格和标签都被忽略。请参阅屏幕截图。

我想看到的结果是在脚本的评论行中给出的。

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AnyDozer

//@version=5
indicator("Test message for alert")

str1 = "\{" + "\n"
str2 = "\t" + "   \"name\": \"___\"," + "\n"
str3 = "          \"secret\": \"___\","+ "\n"
str4 = "  " + "   \"side\": \"buy\"," + "\n"
str5 = "   \"symbol\": \"___\"," + "\n"
str6 = "   \"open\":  {" + "\n"
str7 = "     \"amountType\": \"___\"," + "\n"
str8 = "     \"amount\": \"___\"" + "\n"
str9 = "  }" + "\n"
str0 = "}"

if true
    alert(str1+str2+str3+str4+str5+str6+str7+str8+str9+str0, alert.freq_once_per_bar_close)

plot(0)


// {
//   "name": "___",
//   "secret": "___",
//   "side": "buy",
//   "symbol": "___",
//   "open": {
//     "amountType": "___",
//     "amount": "___"
//   }
// }

We haven't talked for a long time.

Faced with the problem of formatting the text in the message. It is required that the message is displayed in several lines with spaces on the left.

The test sript is given below. No options give the desired result. All spaces and tabs on the left are ignored. See the screenshot.

The result that I would like to see is given in the commented lines of the script.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AnyDozer

//@version=5
indicator("Test message for alert")

str1 = "\{" + "\n"
str2 = "\t" + "   \"name\": \"___\"," + "\n"
str3 = "          \"secret\": \"___\","+ "\n"
str4 = "  " + "   \"side\": \"buy\"," + "\n"
str5 = "   \"symbol\": \"___\"," + "\n"
str6 = "   \"open\":  {" + "\n"
str7 = "     \"amountType\": \"___\"," + "\n"
str8 = "     \"amount\": \"___\"" + "\n"
str9 = "  }" + "\n"
str0 = "}"

if true
    alert(str1+str2+str3+str4+str5+str6+str7+str8+str9+str0, alert.freq_once_per_bar_close)

plot(0)


// {
//   "name": "___",
//   "secret": "___",
//   "side": "buy",
//   "symbol": "___",
//   "open": {
//     "amountType": "___",
//     "amount": "___"
//   }
// }

enter image description here

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

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

发布评论

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

评论(1

北城半夏 2025-02-13 04:09:01

对于任何体面的解析器而言,缺少空间不应该是一个问题。我个人从来没有考虑过我的机器人。

无论如何,您可以尝试使用我们用来在用户输入中添加空格的特殊字符。

//@version=5
indicator("My script")

s = "Line 1\n Line 2\n  Line 3\n   Line 4\n    Line 5"

if (close > open)
    alert(s, alert.freq_once_per_bar_close)
    
plot(close)

这是我下面标记的点。

Missing spaces should not be an issue for any decent parser. I personally never think about those for my bots.

Anyways, you can try using a special character that we use to add spaces in user inputs.

//@version=5
indicator("My script")

s = "Line 1\n Line 2\n  Line 3\n   Line 4\n    Line 5"

if (close > open)
    alert(s, alert.freq_once_per_bar_close)
    
plot(close)

enter image description here

enter image description here

The character is not visible on Stackoverflow but you can find it if you check the built-in MACD's source code for example.

It's the dots I marked below.
enter image description here

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