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
sourcestringThe 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
Returns
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
Returns
EscapeInterpolation(string?)
Escapes the interpolation tokens of Format(string, params object[]).
public static string? EscapeInterpolation(this string? input)
Parameters
inputstringThe input.
Returns
FromCamelCaseToEnumerable(string?)
Converts camel-case string to IEnumerable<T>.
public static IEnumerable<string> FromCamelCaseToEnumerable(this string? input)
Parameters
inputstringThe input.
Returns
FromSnakeToCaps(string?)
Replaces “snake” underscores with caps of first char after the underscore.
public static string? FromSnakeToCaps(this string? input)
Parameters
inputstring
Returns
In(string?, string?)
Determines whether the specified input is in the comma-delimited values.
public static bool In(this string? input, string? delimitedValues)
Parameters
Returns
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
Returns
InDoubleQuotes(string?)
Returns string in double quotes.
public static string? InDoubleQuotes(this string? input)
Parameters
inputstringThe input.
Returns
InDoubleQuotesOrDefault(string?, string)
Returns string in double quotes or default.
public static string? InDoubleQuotesOrDefault(this string? input, string defaultValue)
Parameters
Returns
InsertSpacesBeforeCaps(string?)
Inserts the spaces before caps.
public static IEnumerable<char> InsertSpacesBeforeCaps(this string? input)
Parameters
inputstringThe input.
Returns
IsByte(string?)
Determines whether the specified input is byte.
public static bool IsByte(this string? input)
Parameters
inputstringThe input.
Returns
- bool
trueif 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
Returns
- bool
trueif the specified input is byte; otherwise,false.
IsDecimal(string?)
Determines whether the specified input is decimal.
public static bool IsDecimal(this string? input)
Parameters
inputstringThe input.
Returns
- bool
trueif 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
Returns
- bool
trueif the specified input is decimal; otherwise,false.
IsInteger(string?)
Determines whether the specified input is integer.
public static bool IsInteger(this string? input)
Parameters
inputstringThe input.
Returns
- bool
trueif 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
Returns
- bool
trueif the specified input is integer; otherwise,false.
IsLong(string?)
Determines whether the specified input is long.
public static bool IsLong(this string? input)
Parameters
inputstringThe input.
Returns
- bool
trueif 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
Returns
- bool
trueif 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
inputstringThe input.
Returns
- bool
trueif is telephone number; otherwise,false.
IsUnc(string?)
Determines whether the specified input is a UNC.
public static bool IsUnc(this string? input)
Parameters
inputstringThe input.
Returns
- bool
trueif is a UNC; otherwise,false.
Remarks
📚 https://stackoverflow.com/a/47531093/22944 📚 https://en.wikipedia.org/wiki/Path_(computing)#Uniform_Naming_Convention
IsXml(string?)
Returns true when the specified input is XML-like.
public static bool IsXml(this string? input)
Parameters
inputstringThe input.
Returns
LooksLikeEmailAddress(string?)
Determines whether the specified input looks like an email address.
public static bool LooksLikeEmailAddress(this string? input)
Parameters
inputstringThe input.
Returns
- bool
trueif 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 characters” from strings
public static string RemoveDiacritics(this string input)
Parameters
inputstringthe input
Returns
Examples
input: "Příliš žluťoučký kůň úpěl ďábelské ódy." result: "Prilis zlutoucky kun upel dabelske ody."
Remarks
From Tomas Kubes, http://www.codeproject.com/Articles/31050/String-Extension-Collection-for-C Also, see http://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net
RemoveLeadingZeroWidthNoBreakSpace(string)
Removes any zero width no-break space (ZWNBSP) character from the beginning of the specified string.
public static string RemoveLeadingZeroWidthNoBreakSpace(this string input)
Parameters
inputstringthe input
Returns
Remarks
The ZWNBSP at the beginning of a string has been traditionally called the byte order mark (BOM). For more detail, see https://unicode-explorer.com/c/FEFF
RemoveNullTerminatorCharacters(string)
Removes the “null characters” (C/C++ string terminator characters) from the specified string.
public static string RemoveNullTerminatorCharacters(this string input)
Parameters
inputstringthe input
Returns
Remarks
For more detail, see https://stackoverflow.com/a/2292866/22944
Reverse(string?)
Reverse the string from http://en.wikipedia.org/wiki/Extension_method
public static string? Reverse(this string? input)
Parameters
inputstring
Returns
Remarks
Based on work by Tomas Kubes, http://www.codeproject.com/Articles/31050/String-Extension-Collection-for-C
ToAsciiLettersWithSpacer(string?)
Converts the string into a ASCII letters with spacer \0.
public static string? ToAsciiLettersWithSpacer(this string? input)
Parameters
inputstringThe input.
Returns
ToAsciiLettersWithSpacer(string?, char)
Converts the string into ASCII letters with spacer.
public static string? ToAsciiLettersWithSpacer(this string? input, char spacer)
Parameters
Returns
Remarks
ToBitString(string?)
Converts conventional Boolean magic strings
to either "1" or "0".
public static string? ToBitString(this string? input)
Parameters
inputstringThe input.
Returns
Remarks
Conventional Boolean magic strings:
"yes"or"y""no"or"n"
ToBlogSlug(string?)
Converts the string into a blog slug.
public static string ToBlogSlug(this string? input)
Parameters
inputstringThe input.
Returns
ToCamelCase(string?)
Converts the string into camel case by lower-casing the first character.
public static string? ToCamelCase(this string? input)
Parameters
inputstringThe input.
Returns
ToConfigurationKey(string?)
Convert a command-line args like those defined in ConsoleArgsScalars
to IConfiguration-key format.
public static string ToConfigurationKey(this string? input)
Parameters
inputstringThe input.
Returns
ToDigitsOnly(string?)
Converts the string into digits only.
public static string? ToDigitsOnly(this string? input)
Parameters
inputstringThe input.
Returns
ToInstanceFromXml<T>(string?, ILogger)
Deserializes to a class instance based on the specified raw XML.
public static T? ToInstanceFromXml<T>(this string? input, ILogger logger) where T : class
Parameters
Returns
- T
Type Parameters
TThe specified type to deserialize.
ToIntString(string?)
Prepares a string to be converted to int.
public static string? ToIntString(this string? input)
Parameters
inputstringThe input.
Returns
ToIntString(string?, string)
Prepares a string to be converted to int.
public static string? ToIntString(this string? input, string defaultValue)
Parameters
Returns
ToNumberOfDirectoryLevels(string?)
Returns the number of directory levels
based on the conventions ../ or ..</code>.
public static int ToNumberOfDirectoryLevels(this string? path)
Parameters
pathstringThe path.
Returns
ToNumericString(string?)
Converts the string into a numeric format for parsing.
public static string? ToNumericString(this string? input)
Parameters
inputstringThe 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
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
inputstringThe input.
Returns
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
inputstringThe input.
Returns
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
Returns
Truncate(string?)
Truncates the specified input to 16 characters.
The input.public static string? Truncate(this string? input)
Parameters
inputstring
Returns
Truncate(string?, int)
Truncates the specified input to 16 characters.
The input. The length.public static string? Truncate(this string? input, int length)
Parameters
Returns
Truncate(string?, int, string)
Truncates the specified input.
public static string? Truncate(this string? input, int length, string ellipsis)
Parameters
Returns
WithConfigurationHelpTextSuffix(string?)
Returns the specified string with HelpTextSuffix.
public static string WithConfigurationHelpTextSuffix(this string? input)
Parameters
inputstringThe input.