在Lucee中使用listRemoveDuplicates
时,它会删除重复的值,但仍将分隔符留在值的末尾。
前:
<cfset myUsers = 'sathish,sathish'>
<cfset removeDups = listRemoveDuplicates(myUsers)>
<cfdump var="#removeDups#" />
这会产生输出:
sathish,
但是,在使用Adobe ColdFusion检查此相同功能时,它会生成正确的值(最后没有逗号):
sathish
如何省略Lucee中的逗号分隔符?
答案 0 :(得分:2)
浏览Lucee文档,我发现ListCompact()函数返回正确的值。
<cfset myUsers = 'sathish,sathish'>
<cfset removeDups = listCompact(listRemoveDuplicates(myUsers))>
<cfdump var="#removeDups#" />
答案 1 :(得分:1)
您还可以创建这样的自定义函数:
<cffunction name="UDF_listRemoveDuplicates" access="public">
<cfargument name="list" type="string" required="yes">
<!--- Hash Map to maintain the order --->
<cfset local.hashMap = createObject("java", "java.util.LinkedHashMap").init()>
<!--- Add list values as key to Hash Map --->
<cfloop list="#arguments.list#" index="local.value" delimiters=",">
<cfset local.hashMap[local.value] = 1>
</cfloop>
<!--- Return list of Keys --->
<cfreturn structKeyList(local.hashMap, ",")>
</cffunction>
<cfoutput>#UDF_listRemoveDuplicates("sathish,sathish")#</cfoutput>
这应该适用于两者。 (未在Lucee上测试)