如何使用速度后string.split访问数组中的元素? [英] How to access elements of array after using string.split in Velocity?

查看:206
本文介绍了如何使用速度后string.split访问数组中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用速度模板语言,目前有:

I am using Velocity Templating Language and currently have:

#set ( $stringList = $string.split(",") )

这工作正常,并用,​​作为预期分隔符分割字符串了。

which works fine and splits the string up using a ',' as a delimiter as expected.

我的问题是我现在该如何访问每个元素在$的StringList?

My question is how do i now access each of the elements in the $stringList?

我曾尝试:

$stringList.get(0)
$stringList[0]
$stringList.[0]
${stringList}.get(0)

我使用的速度在JIRA和JIRA碰巧使用Velocity版本1.4,这显然不具有访问数组如上试图支持。

I am using Velocity in JIRA and JIRA happens to use Velocity version 1.4 which apparently doesn't have support for accessing arrays as tried above.

任何帮助很多AP preciated。

Any help is much appreciated.

推荐答案

它的工作原理,当我数组转换为使用Arrays.asList()的列表,然后使用从列表的方法来访问元素。

It works when I convert the array to a List using Arrays.asList() and then use methods from List to access elements.

我添加以下上下文:

context.put("arrays", Arrays.class);

在Velocity模板使用:

In velocity template I use:

#set ( $array = $getarray.getArray() )

$arrays.asList($array).get(0)

通过一个String数组如下:

With a String-Array as follows

new String[] {"test1", "test2", "test3", "test4"};

我得到预期的输出:

I get the expected output:

test1

这篇关于如何使用速度后string.split访问数组中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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