Vbscript| 's Experience |
It's a bit more cumbersome to use in VBScript than in JavaScript. JavaScript can be used without creating a RegExp object, but it is not available in VB. and JavaScript can use regexp.$1 to get pattern matching, but not in VB. Need to use another object and a collection: Matchcollection,match
One example is as follows:
Suppose there is a string with such a
Strnor= "; Northsnow: The snow in the northern, Csdn: The largest developer network in China; CRC: Changchun Rail Bus Co., Ltd.;
String contains a lot of substrings, substring is used; (semicolon) split open, each substring also divided into two parts, the first part of the logo or English name, the latter part of the Chinese name or description. Find the following instructions based on the given identity how do you do that? That's the problem we're going to solve in this case:
The code is as follows:
Dim ostr
Ostr= "; Northsnow: The snow in the northern, Csdn: The largest developer network in China; CRC: Changchun Rail Bus Co., Ltd.;
function GetName (ooid)
Dim objRegExp, Rematchcol,rematch,resubmatch
Dim rValue
Set objregexp=new REGEXP
Objregexp.pattern= ";(" & Ooid & "):([^;] *)"
Objregexp.ignorecase=true
Objregexp.global=true
Set rematchcol= objregexp.execute (OSTR) ' executes the query and returns a match to a matching set
If Rematchcol.count>0 Then
Set rematch = Rematchcol (0) ' places the first matching string in a matching object
Set resubmatch = Rematch.submatches ' Returns a child matching set
If Resubmatch (0) =ooid Then
Rvalue=resubmatch (1)
Else
Rvalue= ""
End If
Else
Rvalue= ""
End If
Getname=rvalue
End Function
Response. Write getName ("Northsnow")
Thank you for reading this article, have comments or suggestions please participate in the comments, or email author, author email:northsnow@163.com