Skip to content

Instantly share code, notes, and snippets.

@spetryjohnson
Last active December 15, 2015 13:59
Show Gist options
  • Save spetryjohnson/5271045 to your computer and use it in GitHub Desktop.
Save spetryjohnson/5271045 to your computer and use it in GitHub Desktop.
public static class StringExtensions {
/// <summary>
/// Null safe value of .Trim(). If the value is null, returns an empty string.
/// </summary>
public static string TrimNullSafe(this string value) {
return (value != null)
? value.Trim()
: String.Empty;
}
}
var upcCode = UPCCode.Text.TrimNullSafe();
if (!String.IsNullOrEmpty(upcCode)) {
// update db
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment