Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression conversion

Status
Not open for further replies.

DougInCanada

Technical User
Feb 1, 2004
98
0
0
CA
I'm a VB.NET newbie but have worked with VB5 & 6 moons ago, and I'm finally giving in to .NET from vbscripting...

The following vbs code was in a script used to create users. It takes into account any hyphens, apostrophes in either the first or last names, as well as corrects for Mc and Mac. Finally, it capitalizes the first letters of the appropritate names. It uses the following function:

Code:
Function ReplacerFunction(wholematchstring,match1,match2,matchpos,source) 
	if len(match1)>1 then 
	'deal with inconvenient fact that the Mcs and Macs are longer than one char
		match1=ucase(left(match1,1)) & trim(right(match1 & " ", len(match1)))
	end if
	ReplacerFunction = match1 & ucase(match2)
	end function

Which is called several times, for example:

Code:
If InStr(strLastName, "-") > 0 then 
                             Set myReplacer = getRef("ReplacerFunction") 

                             With Createobject("vbscript.regexp")
				.Global = True
				.Multiline = True
				.pattern = "(^mc|^mac|^|-|')(\w{1})"
				strLastName = .Replace(strLastName, myReplacer)
			End With
		end if

While I used to use CreateObject in vbs, I've read that I should use

Code:
Imports System.Text.RegularExpressions
at the start of your source code (please correct me if I'm wrong).

Can someone provide some assistance with the .NET syntax for the function and/or the call?

I'm already struggling with the concepts, but I'm very pleased with what I see so far in VB 2010....

Much appreciated,

Doug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top