Home

Awesome

StringExtensions

c# StringExtensions Library provides comprehensive string extension methods that go behold just the common string validation methods extending the .Net System.string class. The idea to create such a library was motivated by the lack of such a StringUtil library such as org.apache.commons.lang3.StringUtils in the the .Net realm. The aim of this library is to serve as a goto library for those wishing to have such a library readily available to incorporate in to new or existing projects.

Installation

Install-Package StringExtensionsLibrary

Usage

Once you have installed the String extension library within your project. String extensions functions will be available on all string types

if("64.233.161.1470".IsValidIPv4()){
	\\do something
}

String Extension functions

Function NameDescription
IsDateTimeChecks if date with dateFormat is parse-able to System.DateTime format returns boolean
ToInt32Converts the string representation of a number to its 32-bit signed integer equivalent
ToInt64Converts the string representation of a number to its 64-bit signed integer equivalent
ToInt16Converts the string representation of a number to its 16-bit signed integer equivalent
ToDecimalConverts the string representation of a number to its System.Decimal equivalent
ToBooleanConverts string to its boolean equivalent
ToBytesConvert a string to its equivalent byte array
SplitToReturns an enumerable collection of the specified type containing the substrings in this instance that are delimited by elements of a specified Char array
ToEnumConverts string to its Enum type,,Checks if string is a member of type T enum before converting. if fails returns default enum
FormatReplaces one or more format items in a specified string with the string representation of a specified object
GetEmptyStringIfNullGets empty String if passed value is of type Null
GetDefaultIfEmptyReturns a default String value if given value is null or empty
IsIntegerIsInteger Function checks if a string is a valid int32 value
IsNumericChecks if a string is a valid floating value
IsAlphaChecks if String contains only Unicode letters
IsAlphaNumericChecks if the String contains only Unicode letters & digits.
IsValidIPv4Checks if a string is valid IPv4
IsEmailAddresschecks if string is a valid email address
TruncateTruncate String and appends trailing ...
CapitalizeReads in a sequence of words from standard input and capitalize each,one (make first letter uppercase; make rest lowercase
FristCharacterGets the first character in string
LastCharacterGets last character in string
ReplaceReplace specified characters with an empty string
RemoveCharsRemove Characters from string
ReverseReverse string
ParseStringToCsvEscapes string by appending quotes for csv output
EncryptEncrypt a string using the supplied key. Encoding is done using RSA encryption
DecryptDecrypt a string using the supplied key. Decoding is done using RSA encryption
CountOccurrencesCount number of occurrences in string based on the string to match
JsonToDictionaryConverts a Json string to dictionary object. function is only applicable for single hierarchy objects i.e no parent child relationships, for parent child relationships JsonToExpanderObject
JsonToExpanderObjectConverts a Json string to ExpandoObject method applicable for multi hierarchy objects i.e,having zero or many parent child relationships
JsonToObjectConverts a Json string to object of type T. function applicable for multi hierarchy objects i.e,having zero or many parent child relationships, Ignore loop references and do not serialize if cycles are detected.
RemovePrefixRemoves the first part of the string, if no match found return original string
RemoveSuffixRemoves the end part of the string, if no match found return original string
EndsWithIgnoreCaseCheck a String ends with another string ignoring the case.
StartsWithIgnoreCaseCheck a String starts with another string ignoring the case.
DoesNotStartWithCheck if a string does not start with prefix
DoesNotEndWithCheck if a string does not end with prefix
AppendSuffixIfMissingAppends the suffix to the end of the string if the string does not already end in the suffix
AppendPrefixIfMissingAppends the prefix to the start of the string if the string does not already start with prefix
CreateHashSha512Convert string to Hash using Sha512
CreateHashSha256Convert string to Hash using Sha256
QueryStringToDictionaryConvert url query string to IDictionary value key pair
ReverseSlashReverse back or forward slashes
ReplaceLineFeedsReplace Line Feeds
GetByteSizeCalculates the amount of bytes occupied by the input string based on the specified encoding argument
LeftExtracts the left part of the input string limited by the length argument
RightExtracts the right part of the input string limited by the length argument
ToTextElementsConverts a string to an Enumerable collection type of string elements
IsNullChecks if a string is null
IsMinLengthChecks if string length is a certain minimum number of characters, does not ignore leading and trailing,white-space.,null strings will always evaluate to false.
IsMaxLengthChecks if string length consists of the specified allowable maximum char length
IsLengthChecks if string length satisfies minimum and maximum allowable char length. does not ignore leading and,trailing white-space
GetLengthGets the number of characters in string checks if string is null
CreateParametersCreate basic dynamic SQL where parameters from a JSON key value pair string