1

在 Lucee 中使用listRemoveDuplicates时,它会删除重复的值,但仍将分隔符留在值的末尾。

前任:

<cfset myUsers = 'sathish,sathish'>
<cfset removeDups = listRemoveDuplicates(myUsers)>

<cfdump var="#removeDups#" />

这将产生输出:

sathish, 

但是,当使用 Adob​​e ColdFusion 检查相同的函数时,它会产生正确的值(末尾没有逗号):

sathish

如何在 Lucee 中省略逗号分隔符?

4

2 回答 2

2

浏览 Lucee 文档,我找到了返回正确值的ListCompact()函数。

<cfset myUsers = 'sathish,sathish'>
<cfset removeDups = listCompact(listRemoveDuplicates(myUsers))>
<cfdump var="#removeDups#" />
于 2016-06-30T12:06:12.640 回答
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 上测试)

于 2016-06-30T12:18:43.050 回答