.Net Regular Expression engine is more powerful than VBScript Regular Expression engine. RegEx is one of the classes of .Net Regular Expression engine. Using the Split method available in RegEx class, we can split a string with Regular Expression pattern. Let us see the implementation below.
Code
Dim oRegex,oArrayList 'Creating instance for RegEx Set oRegex=DotNetFactory.CreateInstance("System.Text.RegularExpressions.Regex","","") 'Creating instance for ArrayList 'this is required to hold the elements since Split method returns String array. Set oArrayList=DotNetFactory.CreateInstance("System.Collections.ArrayList","") 'Splitting the string with Regular Expression Set oArrayList=oArrayList.Adapter(oRegex.Split("quick test professional", "W+")) 'Displaying the elements Msgbox oArrayList(0) Msgbox oArrayList(1) Msgbox oArrayList(2) Set oRegex=Nothing Set oArrayList=Nothing
Synopsis
This method is very useful whenever we need to split a string with Regular Expression pattern.
Note: Since ‘RegEx’ Split method returns String array, VBScript Array cannot hold the elements which are returned by this Split method.
Comments(0)