Skip to content

Latest commit

 

History

History
189 lines (142 loc) · 6.2 KB

StringExtensions.md

File metadata and controls

189 lines (142 loc) · 6.2 KB

Common extensions for System.String

SafeTrim methods

Safely trim a System.String, returns string.Empty in case of null.

Overloads


SafeTrim()

Removes all leading and trailing white-space characters from the current System.String object, returns string.Empty in case of null.

public static string SafeTrim(this string text);

this is shortcut to:

return (text ?? string.Empty).Trim()

SafeTrim(char[])

Removes all leading and trailing occurrences of a set of characters specified in an array from the current System.String object, returns string.Empty in case of null.

public static string SafeTrim(this string text, params char[] trimChars);

this is shortcut to:

return (text ?? string.Empty).Trim(trimChars)

IsEqual methods

Determines whether a System.String has same value to another System.String.

Overloads


IsEqual(string)

Determines whether a System.String has same value to another System.String using StringComparison.CurrentCulture.

public static string IsEqual(this string a, string b);

IsEqual(string, bool)

Determines whether a System.String has same value to another System.String using StringComparison.CurrentCulture with option to ignore case.

public static string IsEqual(this string a, string b, bool ignoreCase);

IsEqual(string, StringComparison)

Determines whether a System.String has same value to another System.String using specified StringComparison.

public static string IsEqual(this string a, string b, StringComparison stringComparison);

IsOrdinalEqual(string)

Determines whether a System.String has same value to another System.String using StringComparison.Ordinal.

public static string IsOrdinalEqual(this string a, string b);

IsOrdinalEqual(string, bool)

Determines whether a System.String has same value to another System.String using StringComparison.Ordinal with option to ignore case.

public static string IsOrdinalEqual(this string a, string b, bool ignoreCase);

IsEqualIgnoreSpaces(string)

Determines whether a System.String has same value (ignore trailing and leading spaces) to another System.String using StringComparison.CurrentCulture.

public static string IsEqualIgnoreSpaces(this string a, string b);

IsEqualIgnoreSpaces(string, bool)

Determines whether a System.String has same value (ignore trailing and leading spaces) to another System.String using StringComparison.CurrentCulture with option to ignore case.

public static string IsEqualIgnoreSpaces(this string a, string b, bool ignoreCase);

IsEqualIgnoreSpaces(string, StringComparison)

Determines whether a System.String has same value (ignore trailing and leading spaces) to another System.String using a specified StringComparison.

public static string IsEqualIgnoreSpaces(this string a, string b, StringComparison stringComparison);

IsOrdinalEqualIgnoreSpaces(string)

Determines whether a System.String has same value (ignore trailing and leading spaces) to another System.String using StringComparison.Ordinal.

public static string IsOrdinalEqualIgnoreSpaces(this string a, string b);

IsOrdinalEqualIgnoreSpaces(string, bool)

Determines whether a System.String has same value (ignore trailing and leading spaces) to another System.String using StringComparison.Ordinal with option to ignore case.

public static string IsOrdinalEqualIgnoreSpaces(this string a, string b, bool ignoreCase);

Contains methods

Determines whether a System.String contains another System.String.

Overloads


Contains(string, bool)

Determines whether a System.String contains another System.String using StringComparison.CurrentCulture with option to ignore case.

public static string Contains(this string text, string search, bool ignoreCase);

Exceptions

  • System.NullReferenceException: if current string is null
  • System.NullReferenceException: if search string is null

Contains(string, StringComparison)

Determines whether a System.String contains another System.String using a specified StringComparison.

public static string Contains(this string text, string search, StringComparison stringComparison);

Exceptions

  • System.NullReferenceException: if current string is null
  • System.NullReferenceException: if search string is null

OrdinalContains(string)

Determines whether a System.String contains another System.String using StringComparison.Ordinal.

public static string OrdinalContains(this string text, string search);

Exceptions

  • System.NullReferenceException: if current string is null
  • System.NullReferenceException: if search string is null

OrdinalContains(string, bool)

Determines whether a System.String contains another System.String using StringComparison.Ordinal with option to ignore case.

public static string OrdinalContains(this string text, string search, bool ignoreCase);

Exceptions

  • System.NullReferenceException: if current string is null
  • System.NullReferenceException: if search string is null