comma(,)
由于列表已作为字符串传递,因此您也将获得双倍的结果。
String
类有一个接受char array
ie 的构造函数,String(char[] value)
所以,你可以试试这个:
<!--- Comma delimited list --->
<cfset local.myList = "s,s,s,n,n,n">
<!--- Convert list to array --->
<cfset local.myCharArray = listToArray(local.myList, ",")>
<!--- Create String object using String(char[] value) contructor --->
<cfset local.objString = createObject(
"java",
"java.lang.String"
).init(
javaCast( "char[]", local.myCharArray )
)>
<!--- Get last index --->
<cfset local.lastIndex = local.objString.lastIndexOf('n') />
<!--- Output: 5 --->
<cfoutput>#local.lastIndex#</cfoutput>
这里是TryCF
.
另一种ArrayList
用于处理列表的方法string
:
<!--- Comma delimited list --->
<cfset local.myList = "s,s,s,no,not,no">
<!--- Convert list to array --->
<cfset local.myCharArray = listToArray(local.myList, ",")>
<!--- Create ArrayList Object --->
<cfset local.objArrayList = createObject(
"java",
"java.util.ArrayList"
).init(
javaCast( "int", arrayLen(local.myCharArray) ) )>
<!--- Add item(s) --->
<cfset local.objArrayList.addAll(local.myCharArray)>
<!--- Get last index --->
<cfset local.lastIndex = local.objArrayList.lastIndexOf("no") />
<cfoutput>#local.lastIndex#</cfoutput>
这里是TryCF
.