I have not determined why trying to use a negated character class with Regex.Replace is not replacing newlines with a space.
Here's some sample code:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string testInput = "This is a test. \n This is a newline. \n this is another newline. This is a, comma";
Console.WriteLine(testInput);
//get rid of line breaks and other letters not allowed
string commentFix = Regex.Replace(testInput, @"[^A-Z\sa-z\.0-9\-\:\;\$]", " ");
commentFix = "\"" + commentFix + "\"";
Console.WriteLine("\n");
Console.WriteLine(commentFix);
Console.ReadLine();
}
}
}
The output of this is:
This is a test.
This is a newline.
this is another newline. This is a, comma
"This is a test.
This is a newline.
this is another newline. This is a comma"
Any ideas? (thanks, this is my first question!)