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.
-
IsNumeric
Checks if a string value is numeric according to you system culture.
-
UcFirst
Emulation of PHPs ucfirst()
-
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.
-
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.
-
ToSecureString
Converts a string into a "SecureString"
-
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.
-
ToCamelCase
Convert a String into CamelCase
-
IsValidEmailAddress
Check wheter a string is an valid e-mail address
-
Truncate
Truncate the specified string based on the given length. Replaces the truncated data to "..."
-
Parse<T>
Parse a string to any other type including nullable types.
-
HttpUtility Helpers
Make easily accessible some functions available in HttpUtility into an Extension.
-
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
-
ContainsAny
Checks if a given string contains any of the characters in the passed array of characters.
-
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
-
ToPersianNumber
Converts English Numbers to Persian Numbers
-
ToProperCase
Converts string to a title case.
-
DefaultIfEmpty
returns default value if string is null or empty or white spaces string
-
IsIsin
Determines if a string is a valid ISIN (International Securities Identification Number) code.
-
IsValidNIP, IsValidREGON, IsValidPESEL
Validation algorithms for Polish identification numbers NIP, REGON & PESEL.
-
IsValidUrl
Returns true when a string is a valid url
-
ToPlural
Returns the plural form of the specified word.
-
toSlug
Generate slugs for friendly urls.
-
IsNotNullOrEmpty
Returns true when a given string is not null or empty
-
Linkify
Takes a string of text and replaces text matching a link pattern to a hyperlink
-
Contains
Provides an overload to String.Contains to specify a StringComparison (i.e. allows for case-insensitive searches).
-
IsValidIPAddress
Validates whether a string is a valid IPv4 address.
-
FirstDayOfMonth / LastDayOfMonth
Simple way to Get the first and last day of the specified date.
-
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.
-
ToEnum
Parse a string value to the given Enum
-
ToInt
It converts string to integer and assigns a default value if the conversion is not a success
-
IsNumeric
Checks if a string value is numeric
-
ToDecimal
Convert string to decimal
-
DefaultIfNull
return default value if string is null
-
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
-
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
-
EqualsAny
Check that the given string is in a list of potential matches. Inspired by StackOverflow answer http://stackoverflow.com/a/20644611/23199
-
Strip
Strip a string of the specified substring or set of characters
-
Inject object properties into string
Supplements String.Format by letting you get properties from objects
-
Email
Send an email using the supplied string.
-
GetMD5
Gets the MD5 value of a given file.
-
ToMd5Hash
Convert a input string to a byte array and compute the hash.
-
Replace
Case-insensitive replace method
-
ContainsAll
Check whether the specified string contains an array of strings for each.
-
Format String
Shortcut for System.String.Format
-
IsStrongPassword
Validates whether a string is compliant with a strong password policy.
-
CSharpCompile
Compiles a string into an assembly. .NET 4
-
ToBytes
Converts a file on a given path to a byte array.
-
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.
-
IsBoolean()
Tells whether a value can be coalesced into a boolean
-
FixPersianChars
متدی برای حل مشکل وارد کردن ي و ك عربی توسط کاربر و تبدیل به ی و ک فارسی. توسط محمد کمائی
-
ToPlural
Returns the plural of a word.
-
CSVSplit
Given a line from a CSV-encoded file, split it into fields.
-
GetSHA1Hash
Calculates the SHA1 hash value of a string and returns it as a base64 string.
-
ToColor
Convert a (A)RGB string to a Silverlight Color object
-
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.
-
Raphe
Compare Strings like in SQL
-
ToStringFormat
StringFormat Extension Style
-
ToInt32
Convert string to int32
-
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.
-
String format
Extention method to string for String.Format
-
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"
-
ToUrlSlug
If you get Turkish inputs you can use this method to create url slugs
-
SplitIntoParts
Splits long string into smaller parts with given length.
-
Or
Returns the first string with a non-empty non-null value.
-
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.
-
Repeat
Repeat a string N times
-
Contains
a case-insensitive version of String.Contains()
-
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.
-
ConvertJsonStringToObject
Converts a JSON string to an object
-
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
-
GetScreenSize
Calculates the visual size of a string if it would be displayed on the screen, i.e. as the text of a TextBlock.
-
ContainsAny
Checks if a given string contains any of the string array.
-
ToStream
Converts a String to a MemoryStream
-
IsNullOrEmpty
This extension increase the readability of your code.
-
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 .
-
Fill
Different way to use String.Format
-
Strip
Strips unwanted characters on the specified string.
-
IndexOfOccurence
Finds the index of the nth occurrence of a string in a string
-
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.
-
ConvertTo
Método de Extensión para convertir un String a cualquier tipo de Dato
-
DeleteChars
Remove from the given string, all characters provided in a params array of chars.
-
TakeFirst
Returns the first X characters from a string.
-
ToSentence
Creates a sentence from a variable name.
-
Reverse
Reverse a string
-
GetStrMoney
this method is convert integer or float money data to separated comma string that is simple to read
-
UcWords
Emulates PHPs ucwords - capitalize each word
-
AsBoolean
Converts a string to a boolean value if possible or throws an exception
-
CSVQuoted
If a string contains a space or a comma or a newline, quotes it, suitable for a field in a CSV file.
-
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.
-
ToInt
tries to parse a string to an int, returns zero if it is unable to parse
-
IsNullOrEmptyThenValue
برای حل مشکل مقدار پیشفرض وقتی مقداری وجود ندارد
-
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.
-
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.
-
RightOf
Return the remainder of a string s after a separator c.
-
DeleteFiles
Delete all files found on the specified folder with a given file extension.
-
ToException
Conveniently produces a exception from a given string.
-
CleanBRTags
Remove HTML <br \> tags from the string
-
ToBytes
Convert a string to a byte array
-
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.
-
EnsureFileNameIsUnique
Ensures given file name will return a unique file name, using the format Filename - Copy, or Filename - Copy (n) where n > 1
-
ContainsNumericChars
returns true if string contains numeric chars
-
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")'
-
FormatSafe
Formats a string safely, without throwing any exceptions. Adds an exception message to the resulting string instead.
-
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;
-
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.
-
ContainsAll
Check if the string contains all the elements in the array.
-
Repeat
for Repeat String .
-
ReverseString
for reverse string
-
ContainsAny
Returns if a given string contains any of the characters provided in a params array of strings.
-
IsValidCodeMelli
صحت کد ملی
-
ExcelColumnIndex
Returns the excel column index from a column name
-
ToReversedDateTime
Takes a DateTime object and reverses it to an SQL type string (yyyy-mm-dd hh:MM:ss)
-
Formating
formating the string with a custom user-defined format. # sign is input characters.
-
GetFirst
get fist n charactor in string
-
Split
Split by expression
-
SplitCamelCase
Split any string using camel case pattern.
-
Uppercase with null check
Converts a string to upper-case but checks for null strings first
-
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."
-
LastChar
Select Last character in string .
-
WithVar
Improve readability of string.Format
-
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.
-
FristChar
Select Frist character in string .
-
IndicesOf
Gets all the indexes in which a certain substring appears within the 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.
-
ContainsNoSpaces
Checks if a string contains no spaces
-
CamelCaseToHumanCase
Turn any string formed with camel case into a human cased string.
-
Slice()
Takes a section of a string given the start and end index within the string.
-
RemoveRightIfPresent
Removes end of string if it equals to parameter, otherwise returns origin 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.
-
ToStringLimit(limit)
Save values checking length
-
Split
Extension method to split string by number of characters.
-
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.
-
ToNullable
Converts a string to a primitive type or an enum type. Faster than tryparse blocks. Easier to use, too. Very efficient.
-
EqualsByValue
Determines whether two String objects have the same value. Null and String.Empty are considered equal values.
-
decimalToTime
Convert decimal in string Timeformat (hh:mm)
-
String.IsNotNullThenTrim
Perform a Trim() when the string is not null. If the string is null the method will return null.
-
RandomString
Return a random string of a chosen length
-
ToFirstAll
This method makes the caps for all words in a string
-
GetMatchValue
Returns a collection of string that matched on the pattern.
-
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.
-
CheckSheba
چک کردن شماره شبا وارد شده جهت درست بودن فرمت و الگوریتم آن
-
StringToTimeSpan
Converts a string to a timespan
-
Stuart Sillitoe
Emulation of PHPs ucfirst()
-
ToDouble
Converts a string to a double
-
CountNonEmptyItemsInStringArray
Method returns the number of non-null or non-empty items wihtin a string array of length n.
-
Anjum Riwi
Parse the string in exact data format with null check
-
IsNullThen
Replaces NULL with the specified replacement value.
-
ReplaceIgnoreCase
ReplaceIgnoreCase
-
Arithmetic Expression Validate
Validate a string arithemetic expression
-
GetBoolString
If you need to show "Yes" or "No" depending on some bool property
-
IsMatchRegex
Check if a string is match with given regular expression pattern
-
Extract
Extract a string from an other string between 2 char
-
IfNullElse
Check if string is null or white spaces and return null alternate value
-
SplitPascalCase
Splits the given string by pascal case.
-
ReverseWords
Reverse Words
-
WeekOfYearISO8601
Gets the number of the week according to the definition of the ISO 8601
-
IsDate
Determines if specified string is DateTime. Its an improvement on Phil Campbell's version
-
IsValidIranianSocialCode
بررسی اعتبار کد ملی
-
Format
string formator,replece string.Format
-
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
-
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.