-6
如何从URL中删除最后一个'/'后的字符串?删除URL中的字符串
例子:<cfset normalURL = "http://test.com/myhome/live">
预期的结果:http://test.com/myhome
如何从URL中删除最后一个'/'后的字符串?删除URL中的字符串
例子:<cfset normalURL = "http://test.com/myhome/live">
预期的结果:http://test.com/myhome
下面是做到这一点的方法之一。从上面的代码
<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
'replace','len','left'和'ListLast'的组合应该有效。 –