-1
有人可以幫我提取破折號( - )和點(。)之間的字符串在ASP經典的URL的最後?如何提取破折號( - )和點(。)之間的字符串在asp經典
例如:
mypizza.com/this-is-my-special-6-pizza-this-week-3256.html
我怎樣才能提取3256
價值?
PS:URL中有很多破折號和一些數字。
有人可以幫我提取破折號( - )和點(。)之間的字符串在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
VBScript中沒有len數組。使用UBound()獲取最後一個索引,並減去1得到倒數第二個項目。 –
謝謝@ Ekkehard.Horner,更正了錯誤使用len和倒數第二選擇的準確性。 –