How to realize the following character conversion

The string "<, S=%AUTHENTICATED (1);%> <%USERNAME (administrator)%><%USERTOKEN(7D7327DD-56EC-4C8A-AE71-2240A3AE2254)%>",
Write a function,
I pass the GetFieldValue ("AUTHENTICATED", S) side return 1, GetFieldValue ("USERNAME", S) by the administrator, GetFieldValue ("USERTOKEN", S), 7D7327DD-56EC-4C8A-AE71-2240A3AE2254, and so on,

How to get the following values, I want to get AUTHENTICATED=1,

Public Function GetFieldValue(FieldName As String, SourTxt as String) As String


End Function

Please master Zhijiao´╝ü

Started by Elroy at December 04, 2016 - 1:18 AM

Pseudo code, probably write, just thinking
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

Posted by Atwood at December 18, 2016 - 1:33 AM

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

Posted by Adeline at December 23, 2016 - 1:57 AM



Private Const S = "<%AUTHENTICATED(1)%><%USERNAME (administrator)%><%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

Posted by Aaron at December 30, 2016 - 2:14 AM

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

Posted by Roy at January 01, 2017 - 2:40 AM

A bit more rigorous:
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

Posted by Roy at January 04, 2017 - 3:26 AM