开发者

Use string function to select all text after specific character

开发者 https://www.devze.com 2023-02-05 06:57 出处:网络
How would I use use a string funct开发者_如何学编程ion to select everything in a variable after the last \"/\"

How would I use use a string funct开发者_如何学编程ion to select everything in a variable after the last "/"

http://domain.com/g34/abctest.html

So in this case I would like to select "abctest.html"

Running ColdFusion 8.

Any suggestions?


Um, a bit strange to give very similar answer within few days, but ListLast looks as most compact and straightforward approach:

<cfset filename = ListLast("http://domain.com/g34/abctest.html","/") />

And yes, IMO you should start with this page before asking such questions on SO.


Joe I'd use the listToArray function, passing the "/" as the delimiter, get the length of the array and get the value in the last slot. See sample below

<cfset str = "http://domain.com/g34/abctest.html"/>
<cfset arr = ListToArray(str,"/","false")/>
<cfset val = arr[ArrayLen(arr)]/>
<cfoutput>#str# : #val#</cfoutput>

produces

http://domain.com/g34/abctest.html : abctest.html

0

精彩评论

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