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.
-
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
-
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.
-
IsNumeric
Checks if a string value is numeric according to you system culture.
-
UcFirst
Emulation of PHPs ucfirst()
-
ToSecureString
Converts a string into a "SecureString"
-
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.
-
Parse<T>
Parse a string to any other type including nullable types.
-
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 "..."
-
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.
-
IsIsin
Determines if a string is a valid ISIN (International Securities Identification Number) code.
-
ToProperCase
Converts string to a title case.
-
ContainsAny
Checks if a given string contains any of the characters in the passed array of characters.
-
ToPersianNumber
Converts English Numbers to Persian Numbers
-
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
-
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.
-
ContainsAll
Check whether the specified string contains an array of strings for each.
-
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.
-
SplitCamelCase
Split any string using camel case pattern.
-
GetMD5
Gets the MD5 value of a given file.
-
ContainsAny
Checks if a given string contains any of the string array.
-
ToDecimal
Convert string to decimal
-
ToInt
It converts string to integer and assigns a default value if the conversion is not a success
-
Uppercase with null check
Converts a string to upper-case but checks for null strings first
-
DefaultIfNull
return default value if string is null
-
ToEnum
Parse a string value to the given Enum
-
EqualsAny
Check that the given string is in a list of potential matches. Inspired by StackOverflow answer http://stackoverflow.com/a/20644611/23199
-
IsValidIPAddress
Validates whether a string is a valid IPv4 address.
-
IsNullOrEmptyOrWhiteSpace
It returns true if string is null or empty or just a white space otherwise it returns false.
-
IsUnicode
IsUnicode
-
IsNumeric
Checks if a string value is numeric
-
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
-
Inject object properties into string
Supplements String.Format by letting you get properties from objects
-
Strip
Strip a string of the specified substring or set of characters
-
IsBoolean()
Tells whether a value can be coalesced into a boolean
-
IsStrongPassword
Validates whether a string is compliant with a strong password policy.
-
Email
Send an email using the supplied string.
-
Replace
Case-insensitive replace method
-
ToMd5Hash
Convert a input string to a byte array and compute the hash.
-
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.
-
CSharpCompile
Compiles a string into an assembly. .NET 4
-
Format String
Shortcut for System.String.Format
-
ToBytes
Converts a file on a given path to a byte array.
-
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"
-
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.
-
Strip
Strips unwanted characters on the specified string.
-
GetSHA1Hash
Calculates the SHA1 hash value of a string and returns it as a base64 string.
-
FixPersianChars
متدی برای حل مشکل وارد کردن ي و ك عربی توسط کاربر و تبدیل به ی و ک فارسی. توسط محمد کمائی
-
ToColor
Convert a (A)RGB string to a Silverlight Color object
-
CSVSplit
Given a line from a CSV-encoded file, split it into fields.
-
ToPlural
Returns the plural of a word.
-
ToStream
Converts a String to a MemoryStream
-
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.
-
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.
-
ToStringFormat
StringFormat Extension Style
-
ToInt32
Convert string to int32
-
SplitIntoParts
Splits long string into smaller parts with given length.
-
String format
Extention method to string for String.Format
-
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
-
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.
-
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.
-
ToUrlSlug
If you get Turkish inputs you can use this method to create url slugs
-
ConvertJsonStringToObject
Converts a JSON string to an object
-
Or
Returns the first string with a non-empty non-null value.
-
CheckSheba
چک کردن شماره شبا وارد شده جهت درست بودن فرمت و الگوریتم آن
-
Contains
a case-insensitive version of String.Contains()
-
UcWords
Emulates PHPs ucwords - capitalize each word
-
ConvertTo
Método de Extensión para convertir un String a cualquier tipo de Dato
-
Fill
Different way to use String.Format
-
Repeat
Repeat a string N times
-
RightOf
Return the remainder of a string s after a separator c.
-
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 .
-
TakeFirst
Returns the first X characters from a string.
-
ToSentence
Creates a sentence from a variable name.
-
AsBoolean
Converts a string to a boolean value if possible or throws an exception
-
IsNull
Essentially the implementation of the sql 'isnull' function, allowing the string type (when null) to be replaced with another value.
-
FormatSafe
Formats a string safely, without throwing any exceptions. Adds an exception message to the resulting string instead.
-
GetParentDirectoryPath
On the layers of the directory path of a directory
-
DeleteChars
Remove from the given string, all characters provided in a params array of chars.
-
IsNullOrEmpty
This extension increase the readability of your code.
-
Reverse
Reverse a string
-
GetStrMoney
this method is convert integer or float money data to separated comma string that is simple to read
-
IndexOfOccurence
Finds the index of the nth occurrence of a string in a string
-
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.
-
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.
-
CSVQuoted
If a string contains a space or a comma or a newline, quotes it, suitable for a field in a CSV file.
-
IsNullOrEmptyThenValue
برای حل مشکل مقدار پیشفرض وقتی مقداری وجود ندارد
-
ToException
Conveniently produces a exception from a given string.
-
DeleteFiles
Delete all files found on the specified folder with a given file extension.
-
ToInt
tries to parse a string to an int, returns zero if it is unable to parse
-
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.
-
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
-
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.
-
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;
-
CamelCaseToHumanCase
Turn any string formed with camel case into a human cased string.
-
Repeat
for Repeat String .
-
ContainsNumericChars
returns true if string contains numeric chars
-
GetFirst
get fist n charactor in string
-
WithVar
Improve readability of string.Format
-
LastChar
Select Last character in string .
-
Split
Extension method to split string by number of characters.
-
Split
Split by expression
-
ExcelColumnIndex
Returns the excel column index from a column name
-
RandomString
Return a random string of a chosen length
-
IsValidCodeMelli
صحت کد ملی
-
ContainsAll
Check if the string contains all the elements in the array.
-
ToReversedDateTime
Takes a DateTime object and reverses it to an SQL type string (yyyy-mm-dd hh:MM:ss)
-
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.
-
Slice()
Takes a section of a string given the start and end index within the string.
-
ContainsAny
Returns if a given string contains any of the characters provided in a params array of strings.
-
ReverseString
for reverse string
-
ToNullable
Converts a string to a primitive type or an enum type. Faster than tryparse blocks. Easier to use, too. Very efficient.
-
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."
-
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.
-
FristChar
Select Frist character in string .
-
SplitPascalCase
Splits the given string by pascal case.
-
Formating
formating the string with a custom user-defined format. # sign is input characters.
-
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
-
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.
-
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.
-
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.
-
ReplaceIgnoreCase
ReplaceIgnoreCase
-
IndicesOf
Gets all the indexes in which a certain substring appears within the string.
-
ToStringLimit(limit)
Save values checking length
-
decimalToTime
Convert decimal in string Timeformat (hh:mm)
-
ToDouble
Converts a string to a double
-
StringToTimeSpan
Converts a string to a timespan
-
RemoveRightIfPresent
Removes end of string if it equals to parameter, otherwise returns origin string
-
IsDate
Determines if specified string is DateTime. Its an improvement on Phil Campbell's version
-
IfNullElse
Check if string is null or white spaces and return null alternate value
-
IsMatchRegex
Check if a string is match with given regular expression pattern
-
IsNullThen
Replaces NULL with the specified replacement value.
-
GetMatchValue
Returns a collection of string that matched on the pattern.
-
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
-
Stuart Sillitoe
Emulation of PHPs ucfirst()
-
Arithmetic Expression Validate
Validate a string arithemetic expression
-
GetBoolString
If you need to show "Yes" or "No" depending on some bool property
-
Anjum Riwi
Parse the string in exact data format with null check
-
CountNonEmptyItemsInStringArray
Method returns the number of non-null or non-empty items wihtin a string array of length n.
-
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.
-
Quote
Add double quotes to the beginning and end of a string. Not taking into account if there are already quotes available.
-
Extract
Extract a string from an other string between 2 char
-
ReverseWords
Reverse Words
-
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
-
Replace char at index
Replace one char at index
-
WeekOfYearISO8601
Gets the number of the week according to the definition of the ISO 8601
-
ToLong
Converts a string into a "Long", if invalid returns 0
-
Format
string formator,replece string.Format
-
IsValidIranianSocialCode
بررسی اعتبار کد ملی
-
EnsureStartsWith
Ensures that a string starts with a given prefix.
-
EnsureEndsWith
Ensures that a string ends with a given suffix.
-
Repeated
Extremely fast string repeater complete with alternate extension for char spans.
-
Difference
Calculates the difference between two strings, returning the remainder of the second string starting from where it differs from the first.
-
IsEmptyOrWhiteSpace
This method will check if a string is empty or consists only of whitespace characters, but not null or containing any other characters. This check is sometimes required in data validation processes.
-
SplitOnUpperCase
Useful for display things like property names like FirstName to First Name.
-
.RemoveExtraWhitespace();
Removed extra whitespace from a string for NET8 and higher.
-
User
test