有以下字符串,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请高手指教!
解决方案 »
- ini文件在纯英文系统下编码为Unicode写入中文问题
- 如果实例化一个对象后,没 Set .. = Nothing 会怎样?
- 如何实现点击一次按钮数据记录后移一个,并在文本框中显示?
- 关于统计结果的表示问题?
- 启动程序时提示:链接文件COMDLG32.DLL到不存在的输出USER32.DLL
- 求助代码优化(小问题)
- 请问各位,哪有msdn中文版的电子书下载
- 怎样使用helpcontextid?
- 帮忙调试一下这个程序
- 多谢大家的支持 对所有在CSDN上对我帮助的网友 说声谢谢了!!
- cttoolbar 控件在win8里显示为黑色,不显示出来,怎办?
- 如何实现读取dat数据并转换为mdb格式的文件
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
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
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
Dim p As Integer
Dim strSubString As String
Dim strArr() As Stringp = 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