/// <summary> /// Trims the end off a string /// </summary> public static string TrimEnd(this string input, string suffixToRemove) { Argument.CheckIfNull(input, "input"); Argument.CheckIfNull(suffixToRemove, "suffixToRemove"); if (input != null && suffixToRemove != null && input.EndsWith(suffixToRemove, StringComparison.CurrentCulture)) { return(input.Substring(0, input.Length - suffixToRemove.Length)); } return(input); }
/// <summary> /// Creates a single separated string out of a list of strings. /// </summary> public static string ToSeparated(this IEnumerable <string> source, string separator) { Argument.CheckIfNull(source, "source"); Argument.CheckIfNull(separator, "separator"); StringBuilder codes = new StringBuilder(); foreach (string code in source) { codes.Append("{0}{1}".FormatWith(code, separator)); } return(codes.ToString().TrimEnd(separator)); }
/// <summary> /// Converts string to lowercase. /// </summary> public static string ToLowercase(this String value) { Argument.CheckIfNull(value, "value"); return(value.ToLower(CultureInfo.CurrentCulture)); }
/// <summary> /// Formats the specified value. /// </summary> public static string FormatWith(this String value, params object[] args) { Argument.CheckIfNull(value, "value"); return(string.Format(CultureInfo.CurrentCulture, value, args)); }
/// <summary> /// Determines whether [is all lower case] [the specified value]. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> public static bool IsAllLowercase(this String value) { Argument.CheckIfNull(value, "value"); return(string.Equals(value.ToLower(CultureInfo.CurrentCulture), value, StringComparison.CurrentCulture)); }
/// <summary> /// Removes special characters from the string /// </summary> public static string RemoveLineBreaksAndCarriageReturnCharacters(this string input) { Argument.CheckIfNull(input, "input"); return(input.Replace("\n", string.Empty).Replace("\r", string.Empty)); }