CSharp examples for System:String Replace
Finds and replaces empty or null within a string
using System.Collections; using System.Text; using System;/*from ww w . j a v a 2 s .c o m*/ public class Main{ /// <summary> /// Finds and replaces empty or null within a string /// </summary> /// <param name="source"></param> /// <param name="replaceWith"></param> /// <returns>Value</returns> public static string ReplaceEmptyOrNull(object source, string replaceWith) { if (source == null || source.ToString() == string.Empty) return replaceWith; return source.ToString(); } /// <summary> /// Finds and replaces empty or null within a string /// </summary> /// <param name="source"></param> /// <param name="replaceWith"></param> /// <returns>source</returns> public static string ReplaceEmptyOrNull(string source, string replaceWith) { if (source == string.Empty || source == null) return replaceWith; return source; } }