mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-12 19:25:00 +00:00
feat: Added util methods for removing duplicate whitespace
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user