Thanks Jon for looking at this for me. I have created a console app that will
show the issue in total. If you have any questions, please feel free to
contact me directly at
ro*@tennsoft.com.
You can just slap this into an empty page and it will compile and run to the
error.
Cheers!
Rob
--------------------------------- CODE
-----------------------------------------------------
/* This code results in the following error:
* An unhandled exception of type 'System.NullReferenceException' occurred
in system.dll
* Additional information: Object reference not set to an instance of an
object.*/
using System;
using System.Text;
using System.Text.RegularExpressions;
namespace SampleCode
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
//creation of the regularexpression object
static regx lineScrub = new regx();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//Create the line to be scrubbed
string line = "This pipe| should be taken out and so should this quote.\"";
//Action of the object - error occurs on this line
line = lineScrub.Replace(line, " ");
//Never gets here.
Console.WriteLine( line );
}
}
//regularexpression object created that inherits the
System.Text.RegularExpressions.Regex object.
class regx : Regex
{
public regx()
{
this.pattern = "\\\"\\|";
}
}
}
-------------------------------- End Code
-------------------------------------------------
"Jon Skeet [C# MVP]" wrote:
Rob <Ro*@discussions.microsoft.comwrote:
I have built a class called DTLineScrub that inherits Regex.
All works well with the code below until I try to do a replace on a string.
It then tells me that the object was not instantiated.
Anyone have an Idea what's going on?
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too