• Home
  • API Documentation
Show / Hide Table of Contents
  • Mozzarella
    • ByteArrayExtensions
      • AsString
      • ToHexString
    • CoalesceOptions
      • None
      • WhiteSpaceAsEmpty
    • EnumerableOfStringExtensions
      • Coalesce
    • ErasableString
      • Clear
      • Dispose
      • ErasableString
      • IsCleared
      • IsDisposed
      • Value
    • StringBuilderExtensions
      • Append
      • AppendIf
      • AppendJoin
      • Contains
      • IndexOf
      • LastIndexOf
      • ToLower
      • ToUpper
      • Trim
      • TrimEnd
      • TrimStart
    • StringExtensions
      • AddPrefix
      • AddSuffix
      • AfterFirst
      • AfterLast
      • BeforeFirst
      • BeforeLast
      • CICompare
      • CIContains
      • CIEquals
      • CIReplace
      • Coalesce
      • Contains
      • ContainsOnly
      • IndexOfFirstDifference
      • IsAllDigits
      • IsAlphanumeric
      • IsNullOrEmpty
      • IsNullOrWhiteSpace
      • IsOnlyAlphas
      • IsOnlyDigits
      • LevenshteinDistanceTo
      • Like
      • NullIfEmpty
      • OCICompare
      • OCIContains
      • OCIEquals
      • OCIReplace
      • OEquals
      • PascalCaseToWords
      • RemoveAllExcept
      • RemoveAllWhiteSpace
      • RemoveNonAlphanumerics
      • RemoveNonAlphas
      • Replace
      • StripNonDigits
      • StripPrefix
      • StripSuffix
      • Truncate
  • Mozzarella.Tests
    • RemoveNonAlphanumerics
      • RemoveNonAlphanumerics_DoesNotRemoveNumerics
      • RemoveNonAlphanumerics_RemovesNonAlphanumerics
      • RemoveNonAlphanumerics_ReturnsEmptyForEmpty
      • RemoveNonAlphanumerics_ReturnsNullForNull
      • RemoveNonAlphanumerics_ReturnsOriginalStringWhenNoCharactersRemoved
    • RemoveNonAlphas
      • RemoveNonAlphas_RemovesNonNumericNonAlphas
      • RemoveNonAlphas_RemovesNumerics
      • RemoveNonAlphas_ReturnsEmptyForEmpty
      • RemoveNonAlphas_ReturnsNullForNull
      • RemoveNonAlphas_ReturnsOriginalStringWhenNoCharactersRemoved

Class StringExtensions

Extension methods for System.String.

Inheritance
System.Object
StringExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Mozzarella
Assembly: cs.temp.dll.dll
Syntax
public static class StringExtensions

Methods

Name Description
AddPrefix(String, String)

If value does NOT start with prefix then returns a new string with the prefix, otherwise returns value.

AddPrefix(String, String, Boolean)

If value ends with prefix then returns a new string without the prefix, otherwise returns value.

AddSuffix(String, String)

If value does NOT end with suffix then returns a new string with the suffix appended, otherwise returns value.

AddSuffix(String, String, Boolean)

If value does NOT end with suffix then returns a new string with the suffix appended, otherwise returns value.

AfterFirst(String, String)

Returns the portion of value that occurs after the first occurrence of searchValue.

AfterFirst(String, String, StringComparison)

Returns the portion of value that occurs after the first occurrence of searchValue.

AfterLast(String, String)

Returns the portion of value that occurs after the last occurrence of searchValue.

AfterLast(String, String, StringComparison)

Returns the portion of value that occurs after the last occurrence of searchValue.

BeforeFirst(String, String)

Returns the portion of value that occurs before the first instance of searchValue.

BeforeFirst(String, String, StringComparison)

Returns the portion of value that occurs before the first instance of searchValue.

BeforeLast(String, String)

Returns the portion of value that occurs before the last instance of searchValue.

BeforeLast(String, String, StringComparison)

Returns the portion of value that occurs before the last instance of searchValue.

CICompare(String, String)

Performs a case insensitive comparison of two strings, returning an integer indicating if they match, or one is less than/greater than the other.

CIContains(String, String)

Returns true if value contains the substring specified by searchValue, ignoring the case of both strings.

CIEquals(String, String)

Performs a case insensitive comparison of two strings, returning a boolean indicating if they match.

CIReplace(String, String, String)

Replaces all instances of a substring in a given string with another using a case insensitve, current culture based comparisoon.

Coalesce(String, CoalesceOptions, String)

Returns otherValue if value is considered empty, otherwise returns value.

Coalesce(String, CoalesceOptions, String[])

Returns value if it is not empty, otherwise returns the first non-empty, non-null, non-whitespace string from otherValues.

Coalesce(String, String)

Returns otherValue if value is null, empty or contains only whitespace characters, otherwise returns value.

Coalesce(String, String[])

Returns value if it is not empty, otherwise returns the first non-empty, non-null, non-whitespace string from otherValues.

Contains(String, String, StringComparison)

Returns true if value contains the substring searchValue as matched according to comparisonMethod.

ContainsOnly(String, Char[])

Returns true if value contains only characters that exist in characters.

ContainsOnly(String, IEnumerable<Char>)

Returns true if value contains only characters that exist in characters.

IndexOfFirstDifference(String, String)

Returns the original character position of the first difference between two strings. If the strings are identical, returns -1.

IsAllDigits(String)

Determines whether value contains only numeric digits.

IsAlphanumeric(String)

Returns true if value contains only (latin) alphabetic or numeric characters (A-Z, a-z, 0-9).

IsNullOrEmpty(String)

Returns true if value is null or empty string.

IsNullOrWhiteSpace(String)

Returns true if value is null, empty string or contains only whitespace characters.

IsOnlyAlphas(String)

Returns true if value contains only (latin) alphabetic characters (A-Z, a-z).

IsOnlyDigits(String)

Returns true if value contains only characters representing numeric digits.

LevenshteinDistanceTo(String, String)

Returns an integer representing the Levenshtein distance (https://en.wikipedia.org/wiki/Levenshtein_distance) between two strings. Often used to detect typos or misspellings by checking for small distances.

Like(String, String, Boolean)

Performs an operation similar to a T-Sql 'like' on a string.

NullIfEmpty(String)

Returns null if value is an empty string, otherwise returns value.

OCICompare(String, String)

Performs a case insensitive ordinal comparison of two strings, returning an integer indicating if they match, or one is less than/greater than the other.

OCIContains(String, String)

Returns true if value contains the substring specified by searchValue, ignoring the case of both strings and using an ordinal comparison.

OCIEquals(String, String)

Performs an "ordinal" and case insensitive comparison of two strings, returning a boolean indicating if they match.

OCIReplace(String, String, String)

Replaces all instances of a substring in a given string with another using an ordinal and case insenstive comparison.

OEquals(String, String)

Performs an "ordinal" comparison of two strings, returning a boolean indicating if they match.

PascalCaseToWords(String)

Converts a string in pascal or camel case to a human readable string of words.

RemoveAllExcept(String, Char[])

Removes all characters that are not (latin) alphabet characters (A-Z, a-z) or numerics (0-9).

RemoveAllExcept(String, IEnumerable<Char>)

Removes all characters that are not (latin) alphabet characters (A-Z, a-z) or numerics (0-9).

RemoveAllWhiteSpace(String)

Removes all whitespace characters, regardless of where they appear in value and returns a new string containing the result.

RemoveNonAlphanumerics(String)

Removes all characters that are not (latin) alphabet characters (A-Z, a-z) or numerics (0-9).

RemoveNonAlphas(String)

Removes all characters that are not (latin) alphabet characters (A-Z, a-z).

Replace(String, String, String, StringComparison)

An overload for System.String.Replace(System.String,System.String) which allows manually specifying the System.StringComparison to use when locating the searchValue within value.

StripNonDigits(String)

Removes all non-digit characters from a string and returns the result.

StripPrefix(String, String)

If value ends with prefix then returns a new string without the prefix, otherwise returns value.

StripPrefix(String, String, Boolean)

If value ends with prefix then returns a new string without the prefix, otherwise returns value.

StripSuffix(String, String)

If value ends with suffix then returns a new string without the suffix, otherwise returns value.

StripSuffix(String, String, Boolean)

If value ends with suffix then returns a new string without the suffix, otherwise returns value.

Truncate(String, Int32)

If value is longer than maxLength it is truncated at that character position, otherwise the original string is returned.

Back to top Copyright (c) 2017 Troy Willmot