2017-07-07 7 views
-6

最後に '/'の後の文字列をURLから削除する方法はありますか?URLから文字列を削除します

例:<cfset normalURL = "http://test.com/myhome/live">

期待される成果:http://test.com/myhome

+0

'replace'、' len'、 'left'、および' ListLast'の組み合わせは、そのトリックを行うべきです。 –

答えて

0

ここでそれを行うための1つの方法です。コード上から

<cfset normalURL = "http://test.com/myhome/live"> 
<cfoutput><p>#normalURL#</p></cfoutput> 

出力:コード上から

http://test.com/myhome/live

<cfset stringAfterLastSlash = ListLast(normalURL,"/")> 
<cfoutput><p>#stringAfterLastSlash#</p></cfoutput> 

出力:

live

上記のコードから
<cfset stringRemovedFromURL = Replace(normalURL,"/#stringAfterLastSlash#","")> 
<cfoutput><p>#stringRemovedFromURL#</p></cfoutput> 

出力:

http://test.com/myhome

You can play with this code and see the results here