有以下字串,S="<%AUTHENTICATED(1)%><%USERNAME(管理員)%><%USERTOKEN(7D7327DD-56EC-4C8A-AE71-2240A3AE2254)%>",
寫一個函式,
我傳 GetFieldValue("AUTHENTICATED",S) 側回傳 1,傳 GetFieldValue("USERNAME",S) 得到 管理員,傳 GetFieldValue("USERTOKEN",S) ,得到 7D7327DD-56EC-4C8A-AE71-2240A3AE2254,以此類推,
如何得到以下值,我要得到AUTHENTICATED=1,
Public Function GetFieldValue(FieldName As String, SourTxt as String) As String
End Function
請高手指教!
uj5u.com熱心網友回復:
偽代碼,大概寫的,只是思路Public Function GetFieldValue(FieldName As String, SourTxt as String) As String
start = instr(FieldName, FieldName & "(") + len(FieldName) + 1
end = instr(FieldName, ")", start) - 1
GetFieldValue = Mid(SourTxt, start, end - start)
End Function
uj5u.com熱心網友回復:
Public Function GetFieldValue(FieldName As String, SourTxt As String) As String
Dim i&, j&
i = InStr(SourTxt, FieldName)
If (i > 0) Then
i = InStr(i, SourTxt, "(") + 1
j = InStr(i, SourTxt, ")")
GetFieldValue = Mid$(SourTxt, i, j - i)
Else
GetFieldValue = ""
End If
End Function
uj5u.com熱心網友回復:
Private Const S = "<%AUTHENTICATED(1)%><%USERNAME(管理員)%><%USERTOKEN(7D7327DD-56EC-4C8A-AE71-2240A3AE2254)%>"
Private Sub Command1_Click()
MsgBox GetData("USERTOKEN", S)
End Sub
Private Function GetData(ByVal Title As String, ByVal inFind As String) As String
Dim mhs As Object
Dim re As Object
Dim mh As Object
GetData = "N/A"
Set re = CreateObject("vbscript.regExp")
re.Global = True
re.IgnoreCase = True
re.Pattern = "<%" & Title & "\(([^\)]*)\)%>"
Set mhs = re.Execute(inFind)
If mhs.Count > 0 Then
Set mh = mhs(0)
GetData = mh.SubMatches(0)
End If
End Function
uj5u.com熱心網友回復:
Public Function GetFieldValue(FieldName As String, SourTxt As String) As String
Dim p As Integer
Dim strSubString As String
Dim strArr() As String
p = InStr(SourTxt, "%" & FieldName)
strSubString = Mid(SourTxt, p + Len(FieldName) + 2)
strArr = Split(strSubString, ")%")
GetFieldValue = IIf(p, strArr(0), "")
End Function
uj5u.com熱心網友回復:
更嚴謹一點:Public Function GetFieldValue(FieldName As String, SourTxt As String) As String
Dim p As Integer
Dim strArr() As String
p = InStr(SourTxt, "%" & FieldName & "(")
strArr = Split(Mid(SourTxt, p + Len(FieldName) + 2), ")%")
GetFieldValue = IIf(p, strArr(0), "")
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/145038.html
上一篇:獲取遍歷出來的(HtmlTextArea)值把它帶到aspx中 在aspx中有一個tempStock.remark = 帶過來的引數
