开发者

ColdFusion | Split Database String

I have the following:

<dd>
    <select id="contactLocation" name="contactLocation" size="1">
        <option value="Online"<cfif attributes.contactLocation eq "Online">selected</cfif>>Online</option>
        <cfoutput query="storeLocations">
        <opt开发者_高级运维ion value="#storeLocations.name#"<cfif attributes.contactLocation eq "#storeLocations.name#">selected</cfif>>#storeLocations.state# - #storeLocations.city#, #left(storeLocations.storeID, 3)#</option>
    </cfoutput>
    </select>

I added the two top cfset variables as I was trying to figure it out. The string in the database returns 111/NAME and I want to remove the forward slash and everything else to the right of it.

Currently with the two variables I added it just returns the first 3 characters but it is only displaying the one row for every single item in the drop down.

How do I remove the forward slash and everything to the right of it within #storeLocations.storeID#

UPDATE:

Actually Now I have it display all 3 characters per row but what if there are only 2 or if there are 4? I am close I just need the last part.


If the separator is ALWAYS a "/" character and the "/" character will not appear in either token, think of this value as a list with a "/" delimiter and just get the last element with listLast:

listLast(storeLocations.storeID, "/")

If the 2nd part could have a "/" in it, but the first part never will, because its a number, then you can just get rid of the first token using listRest:

listRest(storeLocations.storeID, "/")

Edit: Since I can't tell my right from my left...

listFirst(storeLocations.storeID, "/")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜