有没有一种方法可以将多行字符串分配给对象属性? [英] Is there a way to assign a multi-line string to a object property?

查看:94
本文介绍了有没有一种方法可以将多行字符串分配给对象属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以为这样的变量分配多行字符串:

I know that you can assign a multi-line string to a variable like this:

MyVar = 
(
this
is 
a 
string with multiple
lines
)

但是有一种方法可以将上述字符串分配给对象属性?我尝试这样做,但收到错误消息:

But is there a way to assign the above string to an object property? I tried doing it like this but I received an error:

Array := {}
Array["key"] = 
(
this
is 
a 
string with multiple
lines
)

错误提示:

以下变量名称包含非法字符


一个
字符串"

The following variable name contains an illegal character
"this
is
a
string"

我只希望能够在文本编辑器中打开脚本并将多行字符串直接复制并粘贴到编辑器中作为对象的属性.

I just want to be able to open my script in a text editor and copy and paste multiple-line strings directly into the editor as properties of objects.

推荐答案

您必须对Objects使用适当的赋值运算符:=,同样,您的文本也需要用引号引起来.

You have to use the proper assignment operator := with Objects, likewise your text needs be enclosed by Quotes.

尝试:

obj := {}

obj["key"] := 
( 
"this
is 
a 
string with multiple
lines"
)

MsgBox % obj["key"]

或者您可以在下面执行此操作:

Or you can do this below:

x = 
(
this
is 
a 
string with multiple
lines
)

obj["key"] := x

MsgBox % obj["key"]

您还可以像这样构建多行对象:

You can also build a multi-line object like so:

obj := {"key": 
(
"this
is 
a 
string with multiple
lines"
)}

MsgBox % obj["key"]

这篇关于有没有一种方法可以将多行字符串分配给对象属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆