我在經典asp中有一個字符串。經典asp中的split()asp
Dim str
str = "http://stackoverflow.com/questions/ask/code-classic-asp-in-linux"
在上面的字符串中,我想通過在經典asp中使用split()來獲得「代碼」之後的文本。
的結果應該是:「-classic-ASP-在Linux的」
我在經典asp中有一個字符串。經典asp中的split()asp
Dim str
str = "http://stackoverflow.com/questions/ask/code-classic-asp-in-linux"
在上面的字符串中,我想通過在經典asp中使用split()來獲得「代碼」之後的文本。
的結果應該是:「-classic-ASP-在Linux的」
尼爾是對的。但是在VBScript中IndexOf
等效的是InStr
。
Dim str
str = "http://stackoverflow.com/questions/ask/code-classic-asp-in-linux"
'Split
Response.Write Split(str,"-", 2)(1) ' classic-asp-in-linux
'Mid & InStr
Response.Write Mid(str, InStr(str, "-")) ' -classic-asp-in-linux
你應該這樣做:
Dim str, arrSplitted
str = "http://stackoverflow.com/questions/ask/code-classic-asp-in-linux"
arrSplitted = Split(str, "code-")
arrSplitted將返回包含兩個節點,0和1的陣列。節點1應該包含-classic-as-in-linux。
Response.Write arrSplitted(1)
希望它有效,這是幾年前我用過的經典ASP。
Dim str, arrSplitted, tmp
str = "http://stackoverflow.com/questions/ask/code-classic-asp-in-linux"
tmp = split(str, "code")
Response.Write(tmp(UBound(tmp))) 'return the last element of the array.
您也可以使用的Response.Write(分割(STR, 「碼」)(UBound函數(分(STR, 「代碼」)))),但拆分執行兩次,即爲什麼使用'tmp'變量。
這是一個非常舊的帖子,我知道,但也許有人會發現這個有用的......我認爲OP的實際問題是「如何從URL末尾獲取文檔名稱?」答案是在最後一個斜槓之後獲得所有內容。在這裏,我使用InStrRev來查找最後一個斜槓,將其存儲在位置,然後使用Right函數捕獲URL的末尾。
Dim str, tmp
str = "http://stackoverflow.com/questions/ask/code-classic-asp-in-linux"
tmp = InStrRev(str, "/")
str = Right(str, Len(str) - tmp)
Response.write str
如果URL上有一個斜線,那會導致問題,所以在使用中,你會想檢查這種可能性。
我認爲`IndexOf`會比`Split()更好「 – 2011-12-15 15:05:47
你可以通過使用上面的字符串爲例給出IndexOf()的語法。 – Jagadeesh 2011-12-15 15:09:25
@ User:你使用JScript還是VBscript作爲編程語言? – reporter 2011-12-15 15:11:00