All C# extension methods for type string
-
String Extensions
String extensions, download CoreSystem Library from codeplex; http://coresystem.codeplex.com
-
FormatWithMask
Formats a string with the specified mask
-
Encrypt & Decrypt
Encrypt and decrypt a string using the RSACryptoServiceProvider.
-
Strip Html
Removes any HTML or XML tags from a string. Super simple, but I didn't see anything here like it. I've created similar methods in the past to take into account things like <script> blocks, but I'm not worrying about that here.
-
IsNumeric
Checks if a string value is numeric according to you system culture.
-
UcFirst
Emulation of PHPs ucfirst()
-
IsDate
Wraps DateTime.TryParse() and all the other kinds of code you need to determine if a given string holds a value that can be converted into a DateTime object.
-
ComputeHash
Computes the hash of a string using one of the following algorithms: HMAC, HMACMD5, HMACSHA1, HMACSHA256, HMACSHA384, HMACSHA512,MACTripleDES, MD5, RIPEMD160, SHA1, SHA256, SHA384, SHA512.
-
ToCamelCase
Convert a String into CamelCase
-
ToSecureString
Converts a string into a "SecureString"
-
IsValidEmailAddress
Check wheter a string is an valid e-mail address
-
Parse<T>
Parse a string to any other type including nullable types.
-
Truncate
Truncate the specified string based on the given length. Replaces the truncated data to "..."
-
Left
Returns the first few characters of the string with a length specified by the given parameter. If the string's length is less than the given length the complete string is returned. If length is zero or less an empty string is returned
-
HttpUtility Helpers
Make easily accessible some functions available in HttpUtility into an Extension.
-
ContainsAny
Checks if a given string contains any of the characters in the passed array of characters.
-
ToProperCase
Converts string to a title case.
-
IsIsin
Determines if a string is a valid ISIN (International Securities Identification Number) code.
-
IsGuid
Checks to see if a string represents a valid GUID. Source of the function: Original code at https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94072&wa=wsignin1.0#tabs
-
Mask
A set of extension methods that make it easy to mask a string (to protect account numbers or other personal data). For example, you could mask a SSN of 123456789 to be ******789.
-
ToPersianNumber
Converts English Numbers to Persian Numbers
-
IsValidNIP, IsValidREGON, IsValidPESEL
Validation algorithms for Polish identification numbers NIP, REGON & PESEL.
-
DefaultIfEmpty
returns default value if string is null or empty or white spaces string
-
IsValidUrl
Returns true when a string is a valid url
-
toSlug
Generate slugs for friendly urls.
-
Linkify
Takes a string of text and replaces text matching a link pattern to a hyperlink
-
ToPlural
Returns the plural form of the specified word.
-
Contains
Provides an overload to String.Contains to specify a StringComparison (i.e. allows for case-insensitive searches).
-
IsNotNullOrEmpty
Returns true when a given string is not null or empty
-
FirstDayOfMonth / LastDayOfMonth
Simple way to Get the first and last day of the specified date.
-
ToInt
It converts string to integer and assigns a default value if the conversion is not a success
-
ToEnum
Parse a string value to the given Enum
-
IsValidIPAddress
Validates whether a string is a valid IPv4 address.
-
ToDecimal
Convert string to decimal
-
ContainsAll
Check whether the specified string contains an array of strings for each.
-
DefaultIfNull
return default value if string is null
-
IsNumeric
Checks if a string value is numeric
-
IsUnicode
IsUnicode
-
IsNullOrEmptyOrWhiteSpace
It returns true if string is null or empty or just a white space otherwise it returns false.
-
Nl2Br
Convert a NewLine to a Html break
-
GetMD5
Gets the MD5 value of a given file.
-
EqualsAny
Check that the given string is in a list of potential matches. Inspired by StackOverflow answer http://stackoverflow.com/a/20644611/23199
-
Right
Returns the last few characters of the string with a length specified by the given parameter. If the string's length is less than the given length the complete string is returned. If length is zero or less an empty string is returned
-
Inject object properties into string
Supplements String.Format by letting you get properties from objects
-
Email
Send an email using the supplied string.
-
Strip
Strip a string of the specified substring or set of characters
-
Replace
Case-insensitive replace method
-
ToMd5Hash
Convert a input string to a byte array and compute the hash.
-
IsStrongPassword
Validates whether a string is compliant with a strong password policy.
-
IsBoolean()
Tells whether a value can be coalesced into a boolean
-
Format String
Shortcut for System.String.Format
-
ToBytes
Converts a file on a given path to a byte array.
-
CSharpCompile
Compiles a string into an assembly. .NET 4
-
Evaluate/Calculate
This is submitted as two extension methods as they work together. It is based off of an class designed by sfabriz @ http://www.osix.net/modules/article/?id=761 He has another class that does something a little different but I thought this was a wonderful piece of code so encapsulated it here. I only claim authorship of the conversion and not the underlying logic.
-
ContainsAny
Checks if a given string contains any of the string array.
-
ToPlural
Returns the plural of a word.
-
FixPersianChars
متدی برای حل مشکل وارد کردن ي و ك عربی توسط کاربر و تبدیل به ی و ک فارسی. توسط محمد کمائی
-
GetSHA1Hash
Calculates the SHA1 hash value of a string and returns it as a base64 string.
-
CSVSplit
Given a line from a CSV-encoded file, split it into fields.
-
ToColor
Convert a (A)RGB string to a Silverlight Color object
-
FormatSize
Nicely formatted file size. This method will return file size with bytes, KB, MB and GB in it. You can use this alongside the Extension method named FileSize.
-
LeftOf
Returns the left of a string, terminated by a certain character. If the character isn't found the whole string is returned. Ex: string s = "ab-23"; s.LeftOf(s, '-') returns "ab"
-
ToUrlString
takes a string, replacing special characters and spaces with - (one dash per one or many contiguous special charachters or spaces). makes lower-case and trims. good for seo.
-
Raphe
Compare Strings like in SQL
-
ToStringFormat
StringFormat Extension Style
-
ToInt32
Convert string to int32
-
IsGuid
Validate if a String contains a GUID in groups of 8, 4, 4, 4, and 12 digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses.
-
String format
Extention method to string for String.Format
-
SplitCamelCase
Split any string using camel case pattern.
-
SplitIntoParts
Splits long string into smaller parts with given length.
-
ToUrlSlug
If you get Turkish inputs you can use this method to create url slugs
-
ToNameValueCollection
Splits a string into a NameValueCollection, where each "namevalue" is separated by the "OuterSeparator". The parameter "NameValueSeparator" sets the split between Name and Value.
-
Or
Returns the first string with a non-empty non-null value.
-
ConvertJsonStringToObject
Converts a JSON string to an object
-
ToStream
Converts a String to a MemoryStream
-
SplitTo
Splits a string into an enumerable collection of the specified type containing the substrings in this instance that are delimited by elements of a specified Char array
-
Uppercase with null check
Converts a string to upper-case but checks for null strings first
-
Contains
a case-insensitive version of String.Contains()
-
Repeat
Repeat a string N times
-
GetScreenSize
Calculates the visual size of a string if it would be displayed on the screen, i.e. as the text of a TextBlock.
-
Fill
Different way to use String.Format
-
Generates a Hyper Link to redirect user to Authentication form
this method generates a Hyper Link to redirect user to Authentication form . gets Titla attribute of tag and inner Text of Tag and generate tag A . then returns user to referrer page .
-
Strip
Strips unwanted characters on the specified string.
-
UcWords
Emulates PHPs ucwords - capitalize each word
-
IsNullOrEmpty
This extension increase the readability of your code.
-
GetParentDirectoryPath
On the layers of the directory path of a directory
-
IsNull
Essentially the implementation of the sql 'isnull' function, allowing the string type (when null) to be replaced with another value.
-
IndexOfOccurence
Finds the index of the nth occurrence of a string in a string
-
ConvertTo
Método de Extensión para convertir un String a cualquier tipo de Dato
-
TakeFirst
Returns the first X characters from a string.
-
DeleteChars
Remove from the given string, all characters provided in a params array of chars.
-
GetStrMoney
this method is convert integer or float money data to separated comma string that is simple to read
-
Reverse
Reverse a string
-
CSVQuoted
If a string contains a space or a comma or a newline, quotes it, suitable for a field in a CSV file.
-
ToSentence
Creates a sentence from a variable name.
-
AsBoolean
Converts a string to a boolean value if possible or throws an exception
-
RightOf
Return the remainder of a string s after a separator c.
-
TrimDuplicates
Trims or removes duplicate delimited characters and leave only one instance of that character. If you like to have a comma delimited value and you like to remove excess commas, this extension method is for you. Other characters are supported too, this includes pipe and colon.
-
IsNullOrEmptyThenValue
برای حل مشکل مقدار پیشفرض وقتی مقداری وجود ندارد
-
RemoveSpecialCharacters
Sometimes it is required to remove some special characters like carriage return, or new line which can be considered as invalid characters, especially while file processing. This method removes any special characters in the input string which is not included in the allowed special character list.
-
ToInt
tries to parse a string to an int, returns zero if it is unable to parse
-
CombineWith()
Combines two strings (potentially each of them can be null) with an optional given separator the way you expect. Default separator is a single space.
-
ToException
Conveniently produces a exception from a given string.
-
DeleteFiles
Delete all files found on the specified folder with a given file extension.
-
In
Returns true if this string is any of the provided strings. Equivalent to IN operator in SQL. It eliminates the need to write something like 'if (foo == "foo1" || foo == "foo2" || foo == "foo3")'
-
ToBytes
Convert a string to a byte array
-
EnsureFileNameIsUnique
Ensures given file name will return a unique file name, using the format Filename - Copy, or Filename - Copy (n) where n > 1
-
DoesNotEndWith
It returns true if string does not end with the character otherwise returns false. If you pass null or empty string, false will be returned.
-
FormatSafe
Formats a string safely, without throwing any exceptions. Adds an exception message to the resulting string instead.
-
CheckSheba
چک کردن شماره شبا وارد شده جهت درست بودن فرمت و الگوریتم آن
-
CleanBRTags
Remove HTML <br \> tags from the string
-
DoesNotStartWith
It returns true if string does not start with the character otherwise returns false if you pass null or empty string, false will be returned.
-
ContainsNumericChars
returns true if string contains numeric chars
-
IsNullThenEmpty
A handy extension method for System.String that eliminates this pattern when trying to avoid null reference exceptions. if (someString==null) someString=string.Empty;
-
Repeat
for Repeat String .
-
ContainsAll
Check if the string contains all the elements in the array.
-
CamelCaseToHumanCase
Turn any string formed with camel case into a human cased string.
-
LastChar
Select Last character in string .
-
Split
Split by expression
-
GetFirst
get fist n charactor in string
-
ReverseString
for reverse string
-
ContainsAny
Returns if a given string contains any of the characters provided in a params array of strings.
-
IsValidCodeMelli
صحت کد ملی
-
ToReversedDateTime
Takes a DateTime object and reverses it to an SQL type string (yyyy-mm-dd hh:MM:ss)
-
ExcelColumnIndex
Returns the excel column index from a column name
-
WithVar
Improve readability of string.Format
-
InnerTruncate
Truncates the given string by stripping out the center and replacing it with an elipsis so that the beginning and end of the string are retained. For example, "This string has too many characters for its own good."InnerTruncate(32) yields "This string has...its own good."
-
Formating
formating the string with a custom user-defined format. # sign is input characters.
-
NullStringToEmptyString
If input is null, returns empty string. Otherwise returns original input. After using this method, you can use all string methods without the danger of null exception.
-
HasMultipleInstancesOf
Determines whether a string has multiple occurrences of a particular character. May be helpful when parsing file names, or ensuring a particular string has already contains a given character. This may be extended to use strings, rather than a char.
-
Split
Extension method to split string by number of characters.
-
FristChar
Select Frist character in string .
-
ForDatabase
For use with old school ado.net database command parameters. This basically converts the string to System.DBNull.Value if the string is null else it returns the string.
-
ToNullable
Converts a string to a primitive type or an enum type. Faster than tryparse blocks. Easier to use, too. Very efficient.
-
Slice()
Takes a section of a string given the start and end index within the string.
-
ContainsNoSpaces
Checks if a string contains no spaces
-
IndicesOf
Gets all the indexes in which a certain substring appears within the string.
-
TakeFrom
Returns the remaining characters in a target string, starting from a search string. If the search string is not found in the target, it returns the full target string.
-
RandomString
Return a random string of a chosen length
-
LimitTextLength
Limits a piece of text to a certain maximum length for the purpose of showing it to the user as part of some (G)UI or report that has limited space.
-
String.IsNotNullThenTrim
Perform a Trim() when the string is not null. If the string is null the method will return null.
-
RemoveRightIfPresent
Removes end of string if it equals to parameter, otherwise returns origin string
-
decimalToTime
Convert decimal in string Timeformat (hh:mm)
-
IsNullThen
Replaces NULL with the specified replacement value.
-
ToStringLimit(limit)
Save values checking length
-
ToNullable<> Generic String Extension
Converts a string to a primitive type T, or an enum type T. Faster than tryparse blocks. Easier to use, too. Very efficient. Uses generics so the code is cleaner and more robust than doing a separate convert method for each primitive type.
-
IsMatchRegex
Check if a string is match with given regular expression pattern
-
StringToTimeSpan
Converts a string to a timespan
-
IfNullElse
Check if string is null or white spaces and return null alternate value
-
GetMatchValue
Returns a collection of string that matched on the pattern.
-
ToDouble
Converts a string to a double
-
EqualsByValue
Determines whether two String objects have the same value. Null and String.Empty are considered equal values.
-
ToFirstAll
This method makes the caps for all words in a string
-
ReplaceIgnoreCase
ReplaceIgnoreCase
-
Stuart Sillitoe
Emulation of PHPs ucfirst()
-
Anjum Riwi
Parse the string in exact data format with null check
-
Arithmetic Expression Validate
Validate a string arithemetic expression
-
CountNonEmptyItemsInStringArray
Method returns the number of non-null or non-empty items wihtin a string array of length n.
-
SplitPascalCase
Splits the given string by pascal case.
-
GetBoolString
If you need to show "Yes" or "No" depending on some bool property
-
IsDate
Determines if specified string is DateTime. Its an improvement on Phil Campbell's version
-
Extract
Extract a string from an other string between 2 char
-
ReverseWords
Reverse Words
-
WeekOfYearISO8601
Gets the number of the week according to the definition of the ISO 8601
-
IsFilled(), IsEmpty()
IsFilled and IsEmpty provide a more natural (english language) alternative to check if the value of a string is null, empty or filled
-
Format
string formator,replece string.Format
-
IsValidIranianSocialCode
بررسی اعتبار کد ملی
-
ToLong
Converts a string into a "Long", if invalid returns 0
-
Like(searchString) & ReverseLike(compareString)
Extension method compareString.Like(searchString) to compare a string using SQL Like style wildcards, and searchString.ReverseLike(compareString). Wildcards like "a", "a%", "%b", "a%b" and "a%b%c" supported.
-
Replace char at index
Replace one char at index
-
Quote
Add double quotes to the beginning and end of a string. Not taking into account if there are already quotes available.
-
EnsureStartsWith
Ensures that a string starts with a given prefix.
-
EnsureEndsWith
Ensures that a string ends with a given suffix.
-
User
test