Home > Software engineering >  How to implement the following character conversion
How to implement the following character conversion

Time:10-29


Has the following string S="& lt; % % AUTHENTICATED (1) & gt; <% % the USERNAME (admin) & gt; <% USERTOKEN (7 d7327dd c8a - AE71-2240-56 ec - 4 a3ae2254) % & gt;" ,
Write a function that
I preach GetFieldValue (" AUTHENTICATED ", S) returns 1, preach GetFieldValue (" USERNAME ", S) get the administrator, the GetFieldValue (" USERTOKEN ", S), get 7 d7327dd c8a - AE71-2240-56 ec - 4 a3ae2254, by analogy,

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

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


End the Function

Please give advice or comments!

CodePudding user response:

Pseudo code, written about, just thinking
The Public Function GetFieldValue (FieldName As String, SourTxt As String) As String
Start=instr (FieldName, FieldName & amp; "()" + len (FieldName) + 1
End=instr (FieldName, ") ", the start) - 1
GetFieldValue=https://bbs.csdn.net/topics/Mid (SourTxt, start, end - start)
End the Function

CodePudding user response:

 Public Function GetFieldValue (FieldName As String, SourTxt As String) As String 
Dim i& J&

I=InStr (SourTxt, FieldName)
If (I & gt; 0) Then
I=InStr (I, SourTxt, "(") + 1
J=InStr (I, SourTxt, ") ")
GetFieldValue=https://bbs.csdn.net/topics/Mid$(SourTxt, I, j, I)
The Else
GetFieldValuehttps://bbs.csdn.net/topics/=""
End the If
End the Function

CodePudding user response:

 

Private Const S="& lt; % % AUTHENTICATED (1) & gt; <% % the USERNAME (admin) & gt; <% USERTOKEN (7 d7327dd c8a - AE71-2240-56 ec - 4 a3ae2254) % & gt;"

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
As the Object of Dim re
Dim mh As Object

GetData="https://bbs.csdn.net/topics/N/A"

The Set re=CreateObject (" vbscript. RegExp ")
Re. Global=True
Re the IgnoreCase=True
Re. The Pattern="& lt; % "& amp; The Title & amp; "\ [([^ \] *) \ % & gt;"
The Set of MHS=re. The Execute (inFind)
If MHS. Count & gt; 0 Then
The Set of mh=MHS (0)
GetData (0)=https://bbs.csdn.net/topics/mh.SubMatches
End the If
End the Function

CodePudding user response:

 Public Function GetFieldValue (FieldName As String, SourTxt As String) As String 
Dim As Integer p
Dim strSubString As String
Dim strArr () As String

P=InStr (SourTxt, "%" & amp; FieldName)
StrSubString=Mid (SourTxt, p + Len (FieldName) + 2)
StrArr=Split (strSubString, "%")

GetFieldValue=https://bbs.csdn.net/topics/IIf (p, strArr (0), "")
End the Function

CodePudding user response:

A bit more precise:
 Public Function GetFieldValue (FieldName As String, SourTxt As String) As String 
Dim As Integer p
Dim strArr () As String

P=InStr (SourTxt, "%" & amp; FieldName & amp; "(")
StrArr=Split (mids (SourTxt, p + Len (FieldName) + 2), "%")

GetFieldValue=https://bbs.csdn.net/topics/IIf (p, strArr (0), "")
End the Function
  • Related