Table of Contents

Class StringExtensions

Namespace
Songhay.Extensions
Assembly
SonghayCore.dll

Extensions of string.

public static class StringExtensions
Inheritance
StringExtensions
Inherited Members

Methods

CsvSplit(string?)

Splits CSV text format into an array of string.

public static string[]? CsvSplit(this string? source)

Parameters

source string

The source.

Returns

string[]

Remarks

This code is based on “LINQ to TEXT and LINQ to CSV” by Eric Lippert [http://blogs.msdn.com/b/ericwhite/archive/2008/09/30/linq-to-text-and-linq-to-csv.aspx]

EqualsInvariant(string?, string?)

Returns true when the strings are equal without regard to cultural locales or casing.

public static bool EqualsInvariant(this string? input, string? otherString)

Parameters

input string

The input.

otherString string

The other string.

Returns

bool

EqualsInvariant(string?, string?, bool)

Returns true when the strings are equal without regard to cultural locales.

public static bool EqualsInvariant(this string? input, string? otherString, bool ignoreCase)

Parameters

input string

The input.

otherString string

The other string.

ignoreCase bool

Returns

bool

EscapeInterpolation(string?)

Escapes the interpolation tokens of Format(string, params object[]).

public static string? EscapeInterpolation(this string? input)

Parameters

input string

The input.

Returns

string

FromCamelCaseToEnumerable(string?)

Converts camel-case string to IEnumerable<T>.

public static IEnumerable<string> FromCamelCaseToEnumerable(this string? input)

Parameters

input string

The input.

Returns

IEnumerable<string>

FromSnakeToCaps(string?)

Replaces “snake” underscores with caps of first char after the underscore.

public static string? FromSnakeToCaps(this string? input)

Parameters

input string

Returns

string

In(string?, string?)

Determines whether the specified input is in the comma-delimited values.

public static bool In(this string? input, string? delimitedValues)

Parameters

input string

The input.

delimitedValues string

The delimited values.

Returns

bool

In(string?, string?, char)

Determines whether the specified input is in the delimited values.

public static bool In(this string? input, string? delimitedValues, char separator)

Parameters

input string

The input.

delimitedValues string

The delimited values.

separator char

The separator.

Returns

bool

InDoubleQuotes(string?)

Returns string in double quotes.

public static string? InDoubleQuotes(this string? input)

Parameters

input string

The input.

Returns

string

InDoubleQuotesOrDefault(string?, string)

Returns string in double quotes or default.

public static string? InDoubleQuotesOrDefault(this string? input, string defaultValue)

Parameters

input string

The input.

defaultValue string

The default value.

Returns

string

InsertSpacesBeforeCaps(string?)

Inserts the spaces before caps.

public static IEnumerable<char> InsertSpacesBeforeCaps(this string? input)

Parameters

input string

The input.

Returns

IEnumerable<char>

IsByte(string?)

Determines whether the specified input is byte.

public static bool IsByte(this string? input)

Parameters

input string

The input.

Returns

bool

true if the specified input is byte; otherwise, false.

IsByte(string?, Predicate<byte>?)

Determines whether the specified input is byte.

public static bool IsByte(this string? input, Predicate<byte>? secondaryTest)

Parameters

input string

The input.

secondaryTest Predicate<byte>

The secondary test.

Returns

bool

true if the specified input is byte; otherwise, false.

IsDecimal(string?)

Determines whether the specified input is decimal.

public static bool IsDecimal(this string? input)

Parameters

input string

The input.

Returns

bool

true if the specified input is decimal; otherwise, false.

IsDecimal(string?, Predicate<decimal>?)

Determines whether the specified input is decimal.

public static bool IsDecimal(this string? input, Predicate<decimal>? secondaryTest)

Parameters

input string

The input.

secondaryTest Predicate<decimal>

The secondary test.

Returns

bool

true if the specified input is decimal; otherwise, false.

IsInteger(string?)

Determines whether the specified input is integer.

public static bool IsInteger(this string? input)

Parameters

input string

The input.

Returns

bool

true if the specified input is integer; otherwise, false.

IsInteger(string?, Predicate<int>?)

Determines whether the specified input is integer.

public static bool IsInteger(this string? input, Predicate<int>? secondaryTest)

Parameters

input string

The input.

secondaryTest Predicate<int>

The secondary test.

Returns

bool

true if the specified input is integer; otherwise, false.

IsLong(string?)

Determines whether the specified input is long.

public static bool IsLong(this string? input)

Parameters

input string

The input.

Returns

bool

true if the specified input is long; otherwise, false.

IsLong(string?, Predicate<long>?)

Determines whether the specified input is long.

public static bool IsLong(this string? input, Predicate<long>? secondaryTest)

Parameters

input string

The input.

secondaryTest Predicate<long>

The secondary test.

Returns

bool

true if the specified input is long; otherwise, false.

IsTelephoneNumber(string?)

Determines whether the specified input is a telephone number.

public static bool IsTelephoneNumber(this string? input)

Parameters

input string

The input.

Returns

bool

true if is telephone number; otherwise, false.

IsUnc(string?)

Determines whether the specified input is a UNC.

public static bool IsUnc(this string? input)

Parameters

input string

The input.

Returns

bool

true if is a UNC; otherwise, false.

Remarks

LooksLikeEmailAddress(string?)

Determines whether the specified input looks like an email address.

public static bool LooksLikeEmailAddress(this string? input)

Parameters

input string

The input.

Returns

bool

true if seems to be an email address; otherwise, false.

Remarks

“In short, don’t expect a single, usable regex to do a proper job. And the best regex will validate the syntax, not the validity of an e-mail (jhohn@example.com is correct but it will probably bounce…).” [http://stackoverflow.com/questions/201323/how-to-use-a-regular-expression-to-validate-an-email-addresses]

RemoveDiacritics(string)

Remove accent from strings

public static string RemoveDiacritics(this string input)

Parameters

input string

The input.

Returns

string

string without accents

Examples

input: "Příliš žluťoučký kůň úpěl ďábelské ódy." result: "Prilis zlutoucky kun upel dabelske ody."

Remarks

Reverse(string?)

public static string? Reverse(this string? input)

Parameters

input string

Returns

string

Remarks

ToAsciiLettersWithSpacer(string?)

Converts the string into a ASCII letters with spacer \0.

public static string? ToAsciiLettersWithSpacer(this string? input)

Parameters

input string

The input.

Returns

string

ToAsciiLettersWithSpacer(string?, char)

Converts the string into ASCII letters with spacer.

public static string? ToAsciiLettersWithSpacer(this string? input, char spacer)

Parameters

input string

The input.

spacer char

The spacer.

Returns

string

Remarks

ToBlogSlug(string?)

Converts the string into a blog slug.

public static string ToBlogSlug(this string? input)

Parameters

input string

The input.

Returns

string

ToCamelCase(string?)

Converts the string into camel case by lower-casing the first character.

public static string? ToCamelCase(this string? input)

Parameters

input string

The input.

Returns

string

ToConfigurationKey(string?)

Convert a command-line args like those defined in ConsoleArgsScalars to IConfiguration-key format.

public static string ToConfigurationKey(this string? input)

Parameters

input string

The input.

Returns

string

ToDigitsOnly(string?)

Converts the string into digits only.

public static string? ToDigitsOnly(this string? input)

Parameters

input string

The input.

Returns

string

ToIntString(string?)

Prepares a string to be converted to int.

public static string? ToIntString(this string? input)

Parameters

input string

The input.

Returns

string

ToIntString(string?, string)

Prepares a string to be converted to int.

public static string? ToIntString(this string? input, string defaultValue)

Parameters

input string

The input.

defaultValue string

The default value ("0" by default).

Returns

string

ToNumberOfDirectoryLevels(string?)

Returns the number of directory levels based on the conventions ../ or ..</code>.

public static int ToNumberOfDirectoryLevels(this string? path)

Parameters

path string

The path.

Returns

int

ToNumericString(string?)

Converts the string into a numeric format for parsing.

public static string? ToNumericString(this string? input)

Parameters

input string

The input.

Returns

string

Returns a numeric string ready for integer or float parsing.

Remarks

This member does not support parenthesis as indicators of negative numbers.

ToNumericString(string?, string?)

Converts the string into a numeric format for parsing.

public static string? ToNumericString(this string? input, string? defaultValue)

Parameters

input string

The input.

defaultValue string

The default value ("0" by default).

Returns

string

Returns a numeric string ready for integer or float parsing.

Remarks

This member does not support parenthesis as indicators of negative numbers.

ToPascalCase(string?)

Converts the string into camel case by upper-casing the first character.

public static string? ToPascalCase(this string? input)

Parameters

input string

The input.

Returns

string

ToSnakeCase(string?)

Converts the string into camel case then replaces every upper case character with an underscore and its lowercase equivalent.

public static string? ToSnakeCase(this string? input)

Parameters

input string

The input.

Returns

string

ToSubstringInContext(string?, string?, int)

Formats the string into a shortened form, showing the search text in context.

public static string? ToSubstringInContext(this string? input, string? searchText, int contextLength)

Parameters

input string

The input.

searchText string

The search text.

contextLength int

Length of the context.

Returns

string

Truncate(string?)

Truncates the specified input to 16 characters.

The input.
public static string? Truncate(this string? input)

Parameters

input string

Returns

string

Truncate(string?, int)

Truncates the specified input to 16 characters.

The input.The length.
public static string? Truncate(this string? input, int length)

Parameters

input string
length int

Returns

string

Truncate(string?, int, string)

Truncates the specified input.

public static string? Truncate(this string? input, int length, string ellipsis)

Parameters

input string

The input.

length int

The length.

ellipsis string

Returns

string

WithConfigurationHelpTextSuffix(string?)

Returns the specified string with HelpTextSuffix.

public static string WithConfigurationHelpTextSuffix(this string? input)

Parameters

input string

The input.

Returns

string