如何在specman中加入字符串列表?
我有一个要打印的列表:
foo: list of string;
我想创建一个字符串 bar
,它是 foo
元素的串联。 在 Perl 中,我会这样做:
$bar = join " ", @foo;
我能想到的在 Specman 中执行此操作的唯一方法是:
var bar: string = "";
for each in foo {
bar = appendf("%s %s", bar, it);
};
这似乎会产生非常差的性能,因为它为 中的每个元素将
. 有没有更好的方法来做到这一点?bar
复制到自身上foo
I have a list that I want to print:
foo: list of string;
I want to create a string bar
that is the concatenation of the elements of foo
. In Perl I would do:
$bar = join " ", @foo;
The only way I can think of to do this in specman is:
var bar: string = "";
for each in foo {
bar = appendf("%s %s", bar, it);
};
This seems like it would have very poor performance, because it copies bar
onto itself for each element in foo
. Is there any better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还有一个专用函数:
我确信
help str_join
会给您详细信息。 还有其他有用的函数,例如您可能会喜欢的str_match
、str_split
。作为附加提示,也许您应该自己打印电子语言快速参考,请参阅http://www.cadence.com/Community/blogs/fv/存档/2009/06/19/send-us-suggestions-for-updating-the-e-specman-quick-reference-card.aspx。
There is also a dedicated function for this:
I'm sure
help str_join
will give you the details. There are also other useful functions likestr_match
,str_split
which you may like.As an additional hint, maybe you should print yourself the e Language Quick Reference, see http://www.cadence.com/Community/blogs/fv/archive/2009/06/19/send-us-suggestions-for-updating-the-e-specman-quick-reference-card.aspx.
在写问题时,我偶然发现了 to_string() 方法。 我可以使用:
这相当于 Perl 的:
如果我想使用空格,我可以使用:
While writing the question I stumbled across the
to_string()
method. I can use:This is the equivalent of Perl's:
If I want to use spaces I can use: