如何提取破折号( - )和点(。)之间的字符串在asp经典

问题描述:

有人可以帮我提取破折号( - )和点(。)之间的字符串在ASP经典的URL的最后?如何提取破折号( - )和点(。)之间的字符串在asp经典

例如:

mypizza.com/this-is-my-special-6-pizza-this-week-3256.html 

我怎样才能提取3256价值?
PS:URL中有很多破折号和一些数字。

解决! 我找到了答案:

Dim n, strPost 
dashCount = len(urlPost)-len(replace(urlPost,"-","")) 
n=dashCount 
thisURL=split(urlPost,"-") 
strPost=replace(thisURL(n),".html","") 
response.write(strPost) 

这个工作,如果你一定在数字前冲刺。如果你可以在/号码前加上/,则在/中加入另一个替换。

dim s, aSplit 
s = "mypizza.com/this-is-my-special-6-pizza-this-week-3256.html" 
s = replace(s, ".", "-") ' replace any dots with dashes 

aSplit = split(s, "-") ' break s into an array, splitting at dashes. Note it is a zero-based array. 

dim sOut 
sOut = aSplit(ubound(aSplit) - 1) ' get the penultimate entry in the array 
+1

VBScript中没有len数组。使用UBound()获取最后一个索引,并减去1得到倒数第二个项目。 –

+0

谢谢@ Ekkehard.Horner,更正了错误使用len和倒数第二选择的准确性。 –