2017-07-07 100 views
-6

如何从URL中删除最后一个'/'后的字符串?删除URL中的字符串

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

预期的结果:http://test.com/myhome

+0

'replace','len','left'和'ListLast'的组合应该有效。 –

回答

0

下面是做到这一点的方法之一。从上面的代码

<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