Created
December 13, 2013 09:07
-
-
Save sebnilsson/7941692 to your computer and use it in GitHub Desktop.
Helper-functions to ensure string starts/ends with a specific string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class StringExtensions | |
{ | |
public static string EnsureEndsWith( | |
this string value, | |
string endValue, | |
StringComparison comparisonType = StringComparison.CurrentCulture) | |
{ | |
return (value == null || value.EndsWith(endValue, comparisonType)) ? value : (value + endValue); | |
} | |
public static string EnsureStartsWith( | |
this string value, | |
string startValue, | |
StringComparison comparisonType = StringComparison.CurrentCulture) | |
{ | |
return (value == null || value.StartsWith(startValue, comparisonType)) ? value : (startValue + value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment