feat: Added util methods for removing duplicate whitespace

This commit is contained in:
Chris Cameron
2020-08-31 13:37:38 -04:00
parent 28f4818ca3
commit bf8c320d66
2 changed files with 25 additions and 0 deletions

View File

@@ -157,6 +157,21 @@ namespace ICD.Common.Utils.Extensions
return new string(extends.Where(c => !char.IsWhiteSpace(c)).ToArray());
}
/// <summary>
/// Replaces spans of whitespace with a single space.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
[PublicAPI]
[NotNull]
public static string RemoveDuplicateWhitespace([NotNull] this string extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return Regex.Replace(extends, @"\s+", " ");
}
/// <summary>
/// Removes all occurrences of the given string.
/// </summary>

View File

@@ -647,6 +647,16 @@ namespace ICD.Common.Utils
return text == null ? null : text.RemoveWhitespace();
}
/// <summary>
/// Replaces spans of whitespace with a single space.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string RemoveDuplicateWhitespace(string text)
{
return text == null ? null : text.RemoveDuplicateWhitespace();
}
/// <summary>
/// Returns true if the string is entirely whitespace characters, or empty, or null.
/// </summary>