Table of Contents

Class StringExtensions

Namespace
Shift.Common
Assembly
Shift.Common.dll
public static class StringExtensions
Inheritance
StringExtensions
Inherited Members

Methods

CleanSplit(string)

public static string[] CleanSplit(this string text)

Parameters

text string

Returns

string[]

CleanSplit(string, char[])

public static string[] CleanSplit(this string text, char[] delimiters)

Parameters

text string
delimiters char[]

Returns

string[]

CleanTrim(string)

public static string CleanTrim(this string text)

Parameters

text string

Returns

string

Contains(string, string, StringComparison)

public static bool Contains(this string str, string substr, StringComparison comparisonType)

Parameters

str string
substr string
comparisonType StringComparison

Returns

bool

EmptyIfNull(string)

public static string EmptyIfNull(this string value)

Parameters

value string

Returns

string

Format(string, object)

public static string Format(this string format, object arg0)

Parameters

format string
arg0 object

Returns

string

Format(string, object, object)

public static string Format(this string format, object arg0, object arg1)

Parameters

format string
arg0 object
arg1 object

Returns

string

Format(string, object, object, object)

public static string Format(this string format, object arg0, object arg1, object arg2)

Parameters

format string
arg0 object
arg1 object
arg2 object

Returns

string

Format(string, params object[])

public static string Format(this string format, params object[] args)

Parameters

format string
args object[]

Returns

string

HasNoValue(string)

public static bool HasNoValue(this string s)

Parameters

s string

Returns

bool

HasValue(string)

public static bool HasValue(this string s)

Parameters

s string

Returns

bool

IfNullOrEmpty(string, Func<string>)

public static string IfNullOrEmpty(this string value, Func<string> nullValueFactory)

Parameters

value string
nullValueFactory Func<string>

Returns

string

IfNullOrEmpty(string, string)

public static string IfNullOrEmpty(this string value, string nullValue)

Parameters

value string
nullValue string

Returns

string

IsEmpty(string)

public static bool IsEmpty(this string s)

Parameters

s string

Returns

bool

IsNotEmpty(string)

public static bool IsNotEmpty(this string s)

Parameters

s string

Returns

bool

Matches(string, string)

Returns true if a string matches another string.

public static bool Matches(this string value, string other)

Parameters

value string
other string

Returns

bool

Remarks

This is not case-sensitive, two null values match, and any two whitespace values match.

MatchesAny(string, IEnumerable<string>)

Returns true if a string has one or more matches in an array of other strings.

public static bool MatchesAny(this string value, IEnumerable<string> others)

Parameters

value string
others IEnumerable<string>

Returns

bool

MatchesNone(string, IEnumerable<string>)

Returns true if a string has zero matches in an array of other strings.

public static bool MatchesNone(this string value, IEnumerable<string> others)

Parameters

value string
others IEnumerable<string>

Returns

bool

MaxLength(string, int, bool)

public static string MaxLength(this string value, int maxLength, bool addEllipsis = false)

Parameters

value string
maxLength int
addEllipsis bool

Returns

string

NullIf(string, string, bool)

public static string NullIf(this string value, string nullValue, bool ignoreCase = false)

Parameters

value string
nullValue string
ignoreCase bool

Returns

string

NullIfEmpty(string)

public static string NullIfEmpty(this string value)

Parameters

value string

Returns

string

NullIfWhiteSpace(string)

public static string NullIfWhiteSpace(this string value)

Parameters

value string

Returns

string

Parse(string)

Converts a string value into a non-null collection.

public static IEnumerable<string> Parse(this string csv)

Parameters

csv string

Returns

IEnumerable<string>

Remarks

Commas and newlines are assumed to be the delimiters. Empty items are removed from the collection. Leading and trailing whitespace characters are removed from each item in the collection.

StartsWithAny(string, IEnumerable<string>)

Returns true if a string starts with any item in an array of strings.

public static bool StartsWithAny(this string value, IEnumerable<string> others)

Parameters

value string
others IEnumerable<string>

Returns

bool

ToEnumNullable<T>(string, bool)

public static T? ToEnumNullable<T>(this string value, bool ignoreCase = true) where T : struct, Enum

Parameters

value string
ignoreCase bool

Returns

T?

Type Parameters

T

ToEnum<T>(string, bool)

public static T ToEnum<T>(this string value, bool ignoreCase = true) where T : struct, Enum

Parameters

value string
ignoreCase bool

Returns

T

Type Parameters

T

ToEnum<T>(string, Func<string, T>, bool)

public static T ToEnum<T>(this string value, Func<string, T> defaultValueFactory, bool ignoreCase = true) where T : struct, Enum

Parameters

value string
defaultValueFactory Func<string, T>
ignoreCase bool

Returns

T

Type Parameters

T

ToEnum<T>(string, T, bool)

public static T ToEnum<T>(this string value, T defaultValue, bool ignoreCase = true) where T : struct, Enum

Parameters

value string
defaultValue T
ignoreCase bool

Returns

T

Type Parameters

T

ToGuid(string)

public static Guid ToGuid(this string value)

Parameters

value string

Returns

Guid

ToGuid(string, Guid)

public static Guid ToGuid(this string value, Guid @default)

Parameters

value string
default Guid

Returns

Guid

ToGuidNullable(string)

public static Guid? ToGuidNullable(this string value)

Parameters

value string

Returns

Guid?

ToKebabCase(string, bool)

Converts a string value from PascalCase to kebab-case.

public static string ToKebabCase(this string input, bool allowForwardSlash = false)

Parameters

input string
allowForwardSlash bool

Returns

string

Examples

ToKebabCase("ThisIsAnExample") => "this-is-an-example"

ToTitleCase(string)

Converts a string value from PascalCase to Title Case.

public static string ToTitleCase(this string input)

Parameters

input string

Returns

string

Examples

ToTitleCase("ThisIsAnExample") => "This Is An Example"