Skip to content

StringExtensions

The library's largest extension surface: null/blank testing, boolean parsing, slicing/truncation, case conversion (including delegation to TitleCase), Unicode normalization, numeric-character testing, decimal conversion, and string wrapping. (BR-072, BR-074, BR-076) through BR-078

Purpose

  • The library's largest extension surface: null/blank testing, boolean parsing, slicing/truncation, case conversion (including delegation to TitleCase), Unicode normalization, numeric-character testing, decimal conversion, and string wrapping. (BR-072, BR-074, BR-076) through BR-078

Context

  • Namespace: SAIF.Common.Extensions
  • Assembly/package: SAIF.Framework.Common

Public members

Member Signature Purpose
IsNullOrEmpty(this string value) public static bool IsNullOrEmpty(this string value) Extension-method form of string.IsNullOrEmpty.
IsNullOrWhiteSpace(this string value) public static bool IsNullOrWhiteSpace(this string value) Extension-method form of string.IsNullOrWhiteSpace.
ToBoolean(this string value) public static bool ToBoolean(this string value) Returns false for null, otherwise true only if the uppercased value is one of Y/YES/TRUE/1/ON. (BR-072)
Left(this string value, int length) public static string Left(this string value, int length) Returns the leftmost length characters; throws ArgumentOutOfRangeException if length exceeds the string's length. (BR-076)
Right(this string value, int length) public static string Right(this string value, int length) Returns the rightmost length characters; throws ArgumentOutOfRangeException if length exceeds the string's length. (BR-076)
Truncate(this string value, int length) public static string Truncate(this string value, int length) Null-safe clamped truncation using Math.Min(value.Length, length), never throwing. (BR-076)
Repeat(this string value, int count) public static string Repeat(this string value, int count) Concatenates value with itself count times.
ToTitleCase(this string value) public static string ToTitleCase(this string value) Title-cases an entire multi-word string, delegating to SAIF.Common.Utility.TitleCase. (BR-014) through BR-021
ToProperCase(this string value) public static string ToProperCase(this string value) Title-cases a single word, delegating to SAIF.Common.Utility.TitleCase. (BR-015) through BR-020
ReplaceUnicodeCharactersWithAscii(this string value) public static string ReplaceUnicodeCharactersWithAscii(this string value) Folds curly quotes, bullets, dashes, and NUL to their nearest ASCII equivalents; null-safe (returns empty string). (BR-074)
ToLower(this string[] values) public static string[] ToLower(this string[] values) Lower-cases every element of a string array.
ToUpper(this string[] values) public static string[] ToUpper(this string[] values) Upper-cases every element of a string array.
ContainsOnlyNumericCharacters(this string value) public static bool ContainsOnlyNumericCharacters(this string value) True only when every character is a digit and the string is non-null/non-empty, via a \D regex test. (BR-077)
ConvertToDecimalOrZero(this string value) public static decimal ConvertToDecimalOrZero(this string value) Returns 0 for null/whitespace input, otherwise Convert.ToDecimal (which throws FormatException on non-numeric text). (BR-078)
Wrap(this string value, string wrapValue) public static string Wrap(this string value, string wrapValue) Returns $"{wrapValue}{value}{wrapValue}".

Sources

  • Common/SAIF.Common/Extensions/StringExtensions.cs