如何实现以下字符转换
有以下字符串,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
请高手指教! --------------------编程问答-------------------- 伪代码,大概写的,只是思路
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 --------------------编程问答--------------------
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
--------------------编程问答--------------------
--------------------编程问答--------------------
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
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
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
补充:VB , 数据库(包含打印,安装,报表)