I know it\'s kind of the wrong thing to do, but I\'m dealing with a legacy codebase that has NULLS when it means empty strings and vice versa.
I can\'t immediately
I tend to use a global extension method on string called ConvertNull() which converts any null values to an empty string. You can then call this anywhere without your code looking cluttered. If you're using this directly on an aspx page, just make sure you've imported the namespace of the extension methods and then the method will be available to you:
namespace ExtensionMethods
{
using System;
public static class StringExtensionsClass
{
/// Converts null strings to empty strings
/// Input string
/// Original string, or empty string if original string was null
public static string ConvertNull(this string s)
{
return s ?? "";
}
}
}
Then call this on an instance of a string.
Usage:
myStringInstance.ConvertNull().Replace("\r\n", "
");