Home > Software engineering >  How to intercept string
How to intercept string

Time:09-22

Saved in A variable, A XML tag

Example:
A="& lt; Max> 1000 & lt;/max>"

I want to get 1000 this value, how to obtain,


Among them, & lt; Max> & lt;/max> This is possible, if there is no value, I also need to decide,
Numerical length is not sure, at the same time, can be arbitrary length

Refer to

CodePudding user response:

The building Lord consult:
& lt;
 A=" Max> 1000 & lt;/max>" 
I=InStr (1, A, & gt; "" 1) + 1 'to determine a "& gt;" The location of the characters behind
J=InStr (I, A, & lt; "" ) - I "calculation" & gt;" And "& lt;" The number of characters between
If (j=0) Then
MsgBox "no data, the label", 64,
The Else
A=Mid $(A, I, j)
MsgBox. A, 64
End the If

CodePudding user response:

A=replace (a, "& lt; Max>" , "")

CodePudding user response:

refer to the second floor vansoft response:
a=replace (a, "& lt; Max>" , "")


A=replace (a, "& lt;/max>" , "")

After secondary to replace text in leaves,
Determine the length, if it is 0, is not,

CodePudding user response:

 
'the content between the two specified string out
'usage
The debug. Print MidStr (" & lt; Max> 1000 & lt;/max>" , "& lt; Max>" , "& lt;/max>" )
Public Function MidStr (ByVal Str As String, ByVal StartStr As String, ByVal EndStr As String, Optional ByVal Order As Integer=0) As String
Dim As Long L, R As Long
L=InStr (Str, StartStr)
If L=0 Then the Exit Function
L=L + Len (StartStr)
If the Order=0 Then
R=InStr (L, Str, EndStr)
The Else
R=InStrRev (Str, EndStr)
End the If
If R & lt; L Then Exit Function
MidStr=Mid (Str, L, R - L)
End the Function

CodePudding user response:

 Dim As A String 
As Long Dim v
A="& lt; Max> 1000 & lt;/max>"
V=Val (Mid (A, InStr (A, "& gt;" ) + 1))

CodePudding user response:

A regular expression, which must be
  • Related