Class StringHelper
public static class StringHelper
- Inheritance
-
StringHelper
- Inherited Members
Fields
CurrentCulture
public static readonly CultureInfo CurrentCulture
Field Value
Methods
Acronym(string)
public static string Acronym(string text)
Parameters
textstring
Returns
AppendWithEllipsis(string)
public static string AppendWithEllipsis(string str)
Parameters
strstring
Returns
BreakHtml(string)
public static string BreakHtml(string html)
Parameters
htmlstring
Returns
ByteArrayToHex(byte[])
public static string ByteArrayToHex(byte[] value)
Parameters
valuebyte[]
Returns
ByteToHex(byte)
public static string ByteToHex(byte value)
Parameters
valuebyte
Returns
Clean(string)
public static string Clean(string text)
Parameters
textstring
Returns
ContainsAny(string, string[])
Returns true if the text contains any one of the values in the array. This function is not case-sensitive.
public static bool ContainsAny(string text, string[] values)
Parameters
Returns
CreateHashMd5(string, byte[])
Returns an MD5 hash of the input text.
public static string CreateHashMd5(string text, byte[] salt = null)
Parameters
Returns
CreateHashSha256(string, byte[])
Returns an SHA256 hash of the input text.
public static string CreateHashSha256(string text, byte[] salt = null)
Parameters
Returns
DecodeBase64(string)
public static string DecodeBase64(string text)
Parameters
textstring
Returns
DecodeBase64(string, Action<Stream>)
public static void DecodeBase64(string data, Action<Stream> read)
Parameters
DecodeBase64(string, string)
public static object DecodeBase64(string data, string key)
Parameters
Returns
DecodeBase64(string, string, Func<Stream, object>)
public static object DecodeBase64(string data, string key, Func<Stream, object> read)
Parameters
Returns
DecodeBase64(string, string, int, Func<Stream, object>)
public static object DecodeBase64(string data, string key, int saltLength, Func<Stream, object> read)
Parameters
Returns
DecodeBase64Url(string)
public static string DecodeBase64Url(string text)
Parameters
textstring
Returns
DecodeBase64Url(string, Action<Stream>)
public static void DecodeBase64Url(string data, Action<Stream> read)
Parameters
DecodeBase64Url(string, string)
public static object DecodeBase64Url(string data, string key)
Parameters
Returns
DecodeBase64Url(string, string, Func<Stream, object>)
public static object DecodeBase64Url(string data, string key, Func<Stream, object> read)
Parameters
Returns
DecodeBase64Url(string, string, int, Func<Stream, object>)
public static object DecodeBase64Url(string data, string key, int saltLength, Func<Stream, object> read)
Parameters
Returns
DecodeBase64Url<TResult>(string, Func<Stream, TResult>)
public static TResult DecodeBase64Url<TResult>(string data, Func<Stream, TResult> read)
Parameters
Returns
- TResult
Type Parameters
TResult
DecodeBase64<TResult>(string, Func<Stream, TResult>)
public static TResult DecodeBase64<TResult>(string data, Func<Stream, TResult> read)
Parameters
Returns
- TResult
Type Parameters
TResult
EncodeBase64(Action<Stream>)
public static string EncodeBase64(Action<Stream> write)
Parameters
Returns
EncodeBase64(object, string)
public static string EncodeBase64(object data, string key)
Parameters
Returns
EncodeBase64(string)
public static string EncodeBase64(string text)
Parameters
textstring
Returns
EncodeBase64(string, Action<Stream>)
public static string EncodeBase64(string key, Action<Stream> write)
Parameters
Returns
EncodeBase64(string, byte[], Action<Stream>)
public static string EncodeBase64(string key, byte[] salt, Action<Stream> write)
Parameters
Returns
EncodeBase64Url(Action<Stream>)
public static string EncodeBase64Url(Action<Stream> write)
Parameters
Returns
EncodeBase64Url(object, string)
public static string EncodeBase64Url(object data, string key)
Parameters
Returns
EncodeBase64Url(string)
public static string EncodeBase64Url(string text)
Parameters
textstring
Returns
EncodeBase64Url(string, Action<Stream>)
public static string EncodeBase64Url(string key, Action<Stream> write)
Parameters
Returns
EncodeBase64Url(string, byte[], Action<Stream>)
public static string EncodeBase64Url(string key, byte[] salt, Action<Stream> write)
Parameters
Returns
EndsWith(string, string)
public static bool EndsWith(string text, string value)
Parameters
Returns
EndsWithAny(string, string[])
Returns true if the text ends with any one of the values in the array. This function is not case-sensitive.
public static bool EndsWithAny(string text, string[] values)
Parameters
Returns
Equals(string, string)
Returns true if the text equals the value. This function is not case-sensitive. Two null references compare equal to each other.
public static bool Equals(string text, string value)
Parameters
Returns
EqualsAny(string, string[])
Returns true if the text equals any one of the values in the array. This function is not case-sensitive.
public static bool EqualsAny(string text, string[] values)
Parameters
Returns
EqualsCaseSensitive(string, string)
public static bool EqualsCaseSensitive(string text, string value)
Parameters
Returns
EqualsCaseSensitive(string, string, bool)
public static bool EqualsCaseSensitive(string text, string value, bool treatNullAsEmpty)
Parameters
Returns
ExtractInitialsFromName(string)
Given a person's first and last name, we'll make our best guess to extract up to two initials, hopefully representing their first and last name, skipping any middle initials, Jr/Sr/III suffixes, etc. The letters will be returned together in ALL CAPS, e.g. "TW".
The way it parses names for many common styles:
Mason Zhwiti -> MZ mason lowercase zhwiti -> MZ Mason G Zhwiti -> MZ Mason G. Zhwiti -> MZ John Queue Public -> JP John Q. Public, Jr. -> JP John Q Public Jr. -> JP Thurston Howell III -> TH Thurston Howell, III -> TH Malcolm X -> MX A Ron -> AR A A Ron -> AR Madonna -> M Chris O'Donnell -> CO Malcolm McDowell -> MM Robert "Rocky" Balboa, Sr. -> RB 1Bobby 2Tables -> BT Éric Ígor -> ÉÍ 행운의 복숭아 -> 행복
public static string ExtractInitialsFromName(string name)
Parameters
namestringThe full name of a person.
Returns
- string
One to two uppercase initials, without punctuation.
FirstValue(params Func<string>[])
public static string FirstValue(params Func<string>[] getters)
Parameters
Returns
FirstValue(params string[])
public static string FirstValue(params string[] values)
Parameters
valuesstring[]
Returns
HexToByte(string)
public static byte HexToByte(string value)
Parameters
valuestring
Returns
HexToByteArray(string)
public static byte[] HexToByteArray(string value)
Parameters
valuestring
Returns
- byte[]
HexToInt16(string)
public static short HexToInt16(string value)
Parameters
valuestring
Returns
HexToInt32(string)
public static int HexToInt32(string value)
Parameters
valuestring
Returns
HexToInt64(string)
public static long HexToInt64(string value)
Parameters
valuestring
Returns
Int16ToHex(short)
public static string Int16ToHex(short value)
Parameters
valueshort
Returns
Int32ToHex(int)
public static string Int32ToHex(int value)
Parameters
valueint
Returns
Int64ToHex(long)
public static string Int64ToHex(long value)
Parameters
valuelong
Returns
IsFileNameMatch(string, string)
public static bool IsFileNameMatch(string one, string two)
Parameters
Returns
Join(IEnumerable<string>)
public static string Join(IEnumerable<string> items)
Parameters
itemsIEnumerable<string>
Returns
Join(IEnumerable<string>, string)
public static string Join(IEnumerable<string> items, string delimiter)
Parameters
itemsIEnumerable<string>delimiterstring
Returns
Join(IEnumerable<string>, string, string)
public static string Join(IEnumerable<string> items, string delimiter, string qualifier)
Parameters
itemsIEnumerable<string>delimiterstringqualifierstring
Returns
JoinFormat<T>(string, IEnumerable<T>)
public static string JoinFormat<T>(string format, IEnumerable<T> data)
Parameters
formatstringdataIEnumerable<T>
Returns
Type Parameters
T
JoinFormat<T>(string, string, IEnumerable<T>)
public static string JoinFormat<T>(string format, string separator, IEnumerable<T> data)
Parameters
formatstringseparatorstringdataIEnumerable<T>
Returns
Type Parameters
T
Leftmost(string, int)
public static string Leftmost(string text, int count)
Parameters
Returns
Matches(string, params string[])
Returns the collection of all regular-expression matches between the text and each of the patterns in the array. This function is not case-sensitive.
public static MatchCollection Matches(string text, params string[] patterns)
Parameters
Returns
PadLeft(string, string, int)
Left pads the input text using the passed pad.
public static string PadLeft(string text, string pad, int totalWidth)
Parameters
Returns
PadLeftWithHtmlSpaces(string, int)
public static string PadLeftWithHtmlSpaces(string text, int totalWidth)
Parameters
Returns
PadRight(string, string, int)
Right pads the input text using the passed pad.
public static string PadRight(string text, string pad, int totalWidth)
Parameters
Returns
PadRightWithHtmlSpaces(string, int)
public static string PadRightWithHtmlSpaces(string text, int totalWidth)
Parameters
Returns
Remove(string, string[])
Removes the matches for each of the patterns from the input text. This function is not case-sensitive.
public static string Remove(string text, string[] patterns)
Parameters
Returns
RemoveNewLines(string)
Removes newline characters from the input text.
public static string RemoveNewLines(string text)
Parameters
textstring
Returns
RemoveNewLines(string, bool)
Removes newline characters from the input text, substituting a blank space for each newline.
public static string RemoveNewLines(string text, bool addSpace)
Parameters
Returns
RemoveNonAlphanumericCharacters(string)
Removes all non-alphanumeric characters from the input text.
public static string RemoveNonAlphanumericCharacters(string text)
Parameters
textstring
Returns
RemoveWordSpecialCharacters(string)
public static string RemoveWordSpecialCharacters(string input)
Parameters
inputstring
Returns
Replace(string, IEnumerable<string>, string, bool)
Replaces every occurrence of every sub-String within the input text with the specified replacement text.
public static string Replace(string text, IEnumerable<string> findWhat, string replaceWith, bool removeUnderscores)
Parameters
textstringfindWhatIEnumerable<string>replaceWithstringremoveUnderscoresbool
Returns
Replace(string, string, string)
Replaces every occurrence of a sub-String within the input text with the specified replacement text. This function is not case- sensitive.
public static string Replace(string text, string findWhat, string replaceWith)
Parameters
Returns
Replace(string, string, string, StringComparison)
public static string Replace(this string input, string oldValue, string newValue, StringComparison comparisonType)
Parameters
inputstringoldValuestringnewValuestringcomparisonTypeStringComparison
Returns
ReplaceFast(string, string, string, StringComparison)
Performs a very fast text search and replace.
public static string ReplaceFast(string text, string findWhat, string replaceWith, StringComparison comparison)
Parameters
textstringfindWhatstringreplaceWithstringcomparisonStringComparison
Returns
ReplaceFirst(string, string, string)
Replaces the first occurrence of a substring within the input text.
public static string ReplaceFirst(string input, string oldValue, string newValue)
Parameters
Returns
ReplaceHtmlBreaksWithNewLines(string)
public static string ReplaceHtmlBreaksWithNewLines(string text)
Parameters
textstring
Returns
ReplaceHtmlSpecialCharacters(string)
public static string ReplaceHtmlSpecialCharacters(string input)
Parameters
inputstring
Returns
ReplaceLast(string, string, string)
Replaces the last occurrence of a substring within the input text. This function is not case-sensitive.
public static string ReplaceLast(string input, string oldValue, string newValue)
Parameters
Returns
ReplaceNewLinesWithHtmlBreaks(string)
public static string ReplaceNewLinesWithHtmlBreaks(string text)
Parameters
textstring
Returns
ReplaceSpacesWithHtmlSpaces(string)
public static string ReplaceSpacesWithHtmlSpaces(string text)
Parameters
textstring
Returns
ReplaceWords(string, char, params string[])
Removes each of the words in the input String, replacing each character of each replaced word with a character mask. This function is not case-sensitive.
public static string ReplaceWords(string text, char mask, params string[] words)
Parameters
Returns
ReplaceWords(string, params string[])
Removes each of the words in the input String. This function is not case-sensitive.
public static string ReplaceWords(string input, params string[] words)
Parameters
Returns
Reverse(string)
Reverses the input text.
public static string Reverse(string text)
Parameters
textstring
Returns
Rightmost(string, int)
public static string Rightmost(string text, int count)
Parameters
Returns
Sanitize(string, char, bool, char[])
Replace all non-alphanumeric characters from the input text with specified symbol
public static string Sanitize(string value, char separator = '-', bool makeLowercase = true, char[] extraChars = null)
Parameters
Returns
Snip(string, int, string)
public static string Snip(string text, int maxLength, string elipsis = "...")
Parameters
Returns
Split(string)
public static string[] Split(string text)
Parameters
textstring
Returns
- string[]
Split(string, char)
public static string[] Split(string text, char delimiter)
Parameters
Returns
- string[]
Split(string, char[])
public static string[] Split(string text, char[] delimiters)
Parameters
Returns
- string[]
StartsWith(string, string)
public static bool StartsWith(string text, string value)
Parameters
Returns
StartsWithAny(string, string[])
Returns true if the text starts with any one of the values in the array. This function is not case-sensitive.
public static bool StartsWithAny(string text, string[] values)
Parameters
Returns
StripHtml(string)
public static string StripHtml(string html)
Parameters
htmlstring
Returns
StripHtml(string, string)
public static string StripHtml(string html, string placeholder)
Parameters
Returns
StripHtml(string, string, bool)
public static string StripHtml(string html, string placeholder, bool stripExcessSpaces)
Parameters
Returns
StripMarkdown(string, bool)
public static string StripMarkdown(string content, bool stripNewLines = false)
Parameters
Returns
ToIdentifier(string)
public static string ToIdentifier(string value)
Parameters
valuestring
Returns
Trim(string)
public static string Trim(string text)
Parameters
textstring
Returns
TrimAndClean(string)
public static string TrimAndClean(string text)
Parameters
textstring
Returns
TrimInside(string)
public static string TrimInside(string text)
Parameters
textstring
Returns
TruncateString(string, int, bool)
public static string TruncateString(string str, int maxLength, bool appendWithEllipsis = false)
Parameters
Returns
VerifyHashMd5(string, byte[], byte[])
Returns true if the MD5 hash of the input text matches the hash value given.
public static bool VerifyHashMd5(string text, byte[] hash, byte[] salt = null)
Parameters
Returns
VerifyHashMd5(string, string, byte[])
Returns true if the MD5 hash of the input text matches the hash value given.
public static bool VerifyHashMd5(string text, string hash, byte[] salt = null)
Parameters
Returns
VerifyHashSha256(string, byte[], byte[])
Returns true if the SHA256 hash of the input text matches the hash value given.
public static bool VerifyHashSha256(string text, byte[] hash, byte[] salt = null)
Parameters
Returns
VerifyHashSha256(string, string, byte[])
Returns true if the SHA256 hash of the input text matches the hash value given.
public static bool VerifyHashSha256(string text, string hash, byte[] salt = null)
Parameters
Returns
WordWrap(string, int)
Wraps the passed String at the at the next whitespace on or after the total character count has been reached for that line. Uses the environment's new line symbol for the break text.
public static string WordWrap(string text, int characterCountPerLine)
Parameters
Returns
WordWrap(string, int, bool)
Wraps the passed String after the the total character count has been reached (if cutoff is true) or at the next whitespace (if cutoff is false). Uses the environment's new line symbol for the break text.
public static string WordWrap(string text, int characterCountPerLine, bool cutoff)
Parameters
Returns
WordWrap(string, int, bool, string)
Wraps the passed String after the the total character count has been reached (if cutoff is true) or at the next whitespace (if cutoff is false). Uses the specified break-text for line-breaks;
public static string WordWrap(string text, int characterCountPerLine, bool cutoff, string breakText)