Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.
using System;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace RegexWrapper
{
[ClassInterface(ClassInterfaceType.None)]
public class Wrapper : IRegex
{
private Regex _regex;
public Wrapper() { }
public Wrapper(string pattern) { this._regex = new Regex(pattern); }
public void SetPattern(string pattern)
{
this._regex = new Regex(pattern);
}
public bool IsMatch(string text)
{
if (this._regex == null)
throw new InvalidOperationException("A pattern must be set prior to calling IsMatch.");
return this._regex.IsMatch(text);
}
}
public interface IRegex
{
bool IsMatch(string text);
void SetPattern(string pattern);
}
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
http://richnewman.wordpress.com/2007/04/15/a-beginner%E2%80%99s-guide-to-calling-a-net-library-from-excel/
You also may want to look at this:
http://www.cpearson.com/excel/CreatingNETFunctionLib.aspx