2016-11-07 55 views

回答

0

解決! 我找到了答案:

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

這個工作,如果你一定在數字前衝刺。如果你可以在/號碼前加上/,則在/中加入另一個替換。

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和倒數第二選擇的準確性。 –

相關問題