ColdFusion |拆分数据库字符串

时间:2010-09-23 15:17:43

标签: coldfusion

我有以下内容:

<dd>
    <select id="contactLocation" name="contactLocation" size="1">
        <option value="Online"<cfif attributes.contactLocation eq "Online">selected</cfif>>Online</option>
        <cfoutput query="storeLocations">
        <option value="#storeLocations.name#"<cfif attributes.contactLocation eq "#storeLocations.name#">selected</cfif>>#storeLocations.state# - #storeLocations.city#, #left(storeLocations.storeID, 3)#</option>
    </cfoutput>
    </select>

我添加了两个顶级cfset变量,因为我试图找出它。数据库中的字符串返回111 / NAME,我想删除正斜杠和其右边的所有其他内容。

目前我添加了两个变量,它只返回前3个字符,但它只显示下拉列表中每个项目的一行。

如何在#storeLocations.storeID#

中删除正斜杠及其右侧的所有内容

更新

实际上我现在每行显示3个字符,但如果只有2个或者有4个字符怎么办?我很接近我只需要最后一部分。

1 个答案:

答案 0 :(得分:6)

如果分隔符始终为“/”字符且“/”字符不会出现在任一标记中,请将此值视为带有“/”分隔符的列表,并使用{{3}获取最后一个元素}:

listLast(storeLocations.storeID, "/")

如果第二部分中可能有“/”,但第一部分永远不会,因为它是一个数字,那么你可以使用listLast摆脱第一个令牌:

listRest(storeLocations.storeID, "/")

编辑:因为我无法从左边说出我的权利......

listFirst(storeLocations.storeID, "/")
相关问题