【问题标题】:How to extract the string between dash (-) and dot (.) in asp classic如何在asp经典中提取破折号(-)和点(。)之间的字符串
【发布时间】:2016-11-07 23:35:02
【问题描述】:

有人可以帮我提取 ASP Classic 中 URL 末尾的破折号 (-) 和点 (.) 之间的字符串吗?

例如:

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

如何提取3256 值?
PS:URL中有很多破折号和一些数字。

【问题讨论】:

    标签: vbscript asp-classic


    【解决方案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
    

    【讨论】:

    • VBScript 中没有数组的 len。使用 UBound() 得到最后一个索引,减 1 得到倒数第二个。
    • 感谢@Ekkehard.Horner,纠正了对 len 的错误使用和倒数第二个选择的准确性。
    【解决方案2】:

    解决了! 我找到了答案:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多