Class StringHelper
Provides helper methods for string operations.
public static class StringHelper
- Inheritance
-
StringHelper
- Inherited Members
Fields
HexEncoding
Provides hexadecimal encoding functionality.
public static readonly HexEncoding HexEncoding
Field Value
N
Represents the newline character "\n".
public const string N = "\n"
Field Value
R
Represents the carriage return character "\r".
public const string R = "\r"
Field Value
RN
Represents the carriage return and newline characters "\r\n".
public const string RN = "\r\n"
Field Value
Properties
WindowsCyrillic
Gets the Windows Cyrillic encoding (code page 1251).
public static Encoding WindowsCyrillic { get; }
Property Value
Methods
ASCII(ArraySegment<byte>)
Gets the string from an ArraySegment using ASCII encoding.
public static string ASCII(this ArraySegment<byte> v)
Parameters
v
ArraySegment<byte>The ArraySegment of bytes.
Returns
- string
The decoded string.
ASCII(byte[])
Gets the string from a byte array using ASCII encoding.
public static string ASCII(this byte[] v)
Parameters
v
byte[]The byte array.
Returns
- string
The ASCII decoded string.
ASCII(byte[], int, int)
Gets the string from a portion of the byte array using ASCII encoding.
public static string ASCII(this byte[] v, int index, int count)
Parameters
Returns
- string
The decoded string.
ASCII(byte[], uint, int)
Gets the string from a byte array using ASCII encoding with a specified count.
[CLSCompliant(false)]
public static string ASCII(this byte[] v, uint count, int index = 0)
Parameters
Returns
- string
The decoded string.
ASCII(string)
Gets the ASCII encoded bytes for the string.
public static byte[] ASCII(this string v)
Parameters
v
stringThe input string.
Returns
- byte[]
The ASCII byte array.
Base64(byte[])
Converts a byte array to a base64 encoded string.
public static string Base64(this byte[] value)
Parameters
value
byte[]The byte array.
Returns
- string
The base64 encoded string.
Base64(string)
Converts a base64 encoded string to a byte array.
public static byte[] Base64(this string value)
Parameters
value
stringThe base64 encoded string.
Returns
- byte[]
The byte array representation.
CheckBrackets(string, string, string)
Checks whether the string starts with the specified start string and ends with the specified end string.
public static bool CheckBrackets(this string str, string sStart, string sEnd)
Parameters
Returns
- bool
true if the string is enclosed by the specified brackets; otherwise, false.
CompareIgnoreCase(string, string)
Compares two strings for equality, ignoring case.
[Obsolete("Use EqualsIgnoreCase.")]
public static bool CompareIgnoreCase(this string str1, string str2)
Parameters
Returns
- bool
True if the strings are equal ignoring case; otherwise, false.
ComparePaths(string, string)
Compares two file paths for equality after normalizing them.
public static bool ComparePaths(this string path1, string path2)
Parameters
Returns
- bool
true if the paths are equal; otherwise, false.
ContainsIgnoreCase(string, string)
Determines whether the first string contains the second string, ignoring case.
public static bool ContainsIgnoreCase(this string str1, string str2)
Parameters
Returns
- bool
True if str1 contains str2 when ignoring case; otherwise, false.
Cyrillic(ArraySegment<byte>)
Gets the string from an ArraySegment using Windows Cyrillic encoding.
public static string Cyrillic(this ArraySegment<byte> v)
Parameters
v
ArraySegment<byte>The ArraySegment of bytes.
Returns
- string
The decoded string.
Cyrillic(byte[])
Gets the string from a byte array using Windows Cyrillic encoding.
public static string Cyrillic(this byte[] v)
Parameters
v
byte[]The byte array.
Returns
- string
The decoded string.
Cyrillic(byte[], int, int)
Gets the string from a portion of the byte array using Windows Cyrillic encoding.
public static string Cyrillic(this byte[] v, int index, int count)
Parameters
Returns
- string
The decoded string.
Cyrillic(byte[], uint, int)
Gets the string from a byte array using Windows Cyrillic encoding with a specified count.
[CLSCompliant(false)]
public static string Cyrillic(this byte[] v, uint count, int index = 0)
Parameters
Returns
- string
The decoded string.
Cyrillic(string)
Gets the Windows Cyrillic encoded bytes for the string.
public static byte[] Cyrillic(this string v)
Parameters
v
stringThe input string.
Returns
- byte[]
The Windows Cyrillic byte array.
DataEscape(string)
Escapes URL data.
public static string DataEscape(this string url)
Parameters
url
stringThe URL data to escape.
Returns
- string
An escaped URL data string.
DataUnEscape(string)
Unescapes URL data.
public static string DataUnEscape(this string url)
Parameters
url
stringThe URL data to unescape.
Returns
- string
An unescaped URL data string.
Default(ArraySegment<byte>)
Gets the string from an ArraySegment using the default encoding.
public static string Default(this ArraySegment<byte> v)
Parameters
v
ArraySegment<byte>The ArraySegment of bytes.
Returns
- string
The decoded string.
Default(byte[])
Gets the string from a byte array using the default encoding.
public static string Default(this byte[] v)
Parameters
v
byte[]The byte array.
Returns
- string
The string decoded from the byte array.
Default(byte[], int, int)
Gets the string from a portion of the byte array using the default encoding.
public static string Default(this byte[] v, int index, int count)
Parameters
Returns
- string
The decoded string.
Default(byte[], uint, int)
Gets the string from a byte array using the default encoding with a specified count.
[CLSCompliant(false)]
public static string Default(this byte[] v, uint count, int index = 0)
Parameters
Returns
- string
The decoded string.
Default(string)
Gets the default encoding bytes for the string.
public static byte[] Default(this string v)
Parameters
v
stringThe input string.
Returns
- byte[]
The byte array in default encoding.
Digest(byte[])
Converts the byte array digest to its hexadecimal string representation.
public static string Digest(this byte[] digest)
Parameters
digest
byte[]The byte array digest.
Returns
- string
The hexadecimal string.
Digest(byte[], int?, int)
Converts a portion of the byte array digest to its hexadecimal string representation.
public static string Digest(this byte[] digest, int? length, int index = 0)
Parameters
digest
byte[]The byte array digest.
length
int?The number of bytes to process.
index
intThe starting index in the array.
Returns
- string
The hexadecimal string.
Duplicates(IEnumerable<string>)
Returns the duplicate strings from the provided collection, ignoring case.
public static IEnumerable<string> Duplicates(this IEnumerable<string> items)
Parameters
items
IEnumerable<string>The collection of strings.
Returns
- IEnumerable<string>
An enumerable collection of duplicate strings.
EndsWithIgnoreCase(string, string)
Determines whether the string ends with the specified substring, ignoring case.
public static bool EndsWithIgnoreCase(this string str1, string str2)
Parameters
Returns
- bool
True if str1 ends with str2 ignoring case; otherwise, false.
EqualsIgnoreCase(string, string)
Determines whether two strings are equal, ignoring case.
public static bool EqualsIgnoreCase(this string str1, string str2)
Parameters
Returns
- bool
True if the strings are equal ignoring case; otherwise, false.
FastIndexOf(string, string)
Searches for the specified pattern in the source string and returns the zero-based index of its first occurrence.
public static int FastIndexOf(this string source, string pattern)
Parameters
Returns
- int
The index of the first occurrence; otherwise, -1 if not found.
GetAndClear(StringBuilder)
Retrieves the content of the StringBuilder and then clears it.
public static string GetAndClear(this StringBuilder builder)
Parameters
builder
StringBuilderThe StringBuilder.
Returns
- string
The content of the StringBuilder before it was cleared.
GetDeterministicHashCode(string)
Calculates a deterministic hash code for the specified string.
public static int GetDeterministicHashCode(this string value)
Parameters
value
stringThe string to hash.
Returns
- int
An integer hash code computed deterministically.
GetLangCode(string)
Gets the two-letter ISO language code from the provided culture name.
public static string GetLangCode(this string cultureName)
Parameters
cultureName
stringThe culture name.
Returns
- string
The two-letter ISO language code.
GetString(Encoding, ArraySegment<byte>)
Decodes an ArraySegment of bytes into a string using the specified encoding.
public static string GetString(this Encoding encoding, ArraySegment<byte> buffer)
Parameters
encoding
EncodingThe encoding to use.
buffer
ArraySegment<byte>The ArraySegment of bytes.
Returns
- string
The decoded string.
Hex(ArraySegment<byte>)
Gets the string from an ArraySegment using hexadecimal encoding.
public static string Hex(this ArraySegment<byte> v)
Parameters
v
ArraySegment<byte>The ArraySegment of bytes.
Returns
- string
The decoded hexadecimal string.
Hex(byte[])
Gets the string from a byte array using hexadecimal encoding.
public static string Hex(this byte[] v)
Parameters
v
byte[]The byte array.
Returns
- string
The hexadecimal decoded string.
Hex(byte[], int, int)
Gets the string from a portion of the byte array using hexadecimal encoding.
public static string Hex(this byte[] v, int index, int count)
Parameters
Returns
- string
The decoded hexadecimal string.
Hex(byte[], uint, int)
Gets the string from a byte array using hexadecimal encoding with a specified count.
[CLSCompliant(false)]
public static string Hex(this byte[] v, uint count, int index = 0)
Parameters
Returns
- string
The decoded hexadecimal string.
Hex(string)
Gets the hexadecimal encoded bytes for the string.
public static byte[] Hex(this string v)
Parameters
v
stringThe input string.
Returns
- byte[]
The hexadecimal byte array.
IndexOfIgnoreCase(string, string, int)
Returns the zero-based index of the first occurrence of the specified substring, ignoring case.
public static int IndexOfIgnoreCase(this string str1, string str2, int index = -1)
Parameters
str1
stringThe string to search.
str2
stringThe substring to locate.
index
intThe starting index for the search. Defaults to -1 for beginning.
Returns
- int
The index of the first occurrence, or -1 if not found.
Intern(string)
Interns the specified string.
public static string Intern(this string str)
Parameters
str
stringThe string to intern.
Returns
- string
The interned string.
IsDigit(char)
Determines whether the specified character is a digit.
public static bool IsDigit(this char c)
Parameters
c
charThe character to test.
Returns
- bool
True if the character is a digit; otherwise, false.
IsEmpty(SecureString)
Determines whether the specified secure string is empty.
public static bool IsEmpty(this SecureString secureString)
Parameters
secureString
SecureStringThe secure string to check.
Returns
- bool
true if the secure string is null or empty; otherwise, false.
IsEmpty(string)
Checks if the string is null or empty.
public static bool IsEmpty(this string str)
Parameters
str
stringThe string to check.
Returns
- bool
True if the string is null or empty; otherwise, false.
IsEmpty(string, string)
Returns default value if the string is null or empty; otherwise, returns the original string.
public static string IsEmpty(this string str, string defaultValue)
Parameters
Returns
- string
Default value or original string.
IsEmpty(StringBuilder)
Determines whether the StringBuilder is empty.
public static bool IsEmpty(this StringBuilder builder)
Parameters
builder
StringBuilderThe StringBuilder to evaluate.
Returns
- bool
True if the StringBuilder is empty; otherwise, false.
IsEmptyOrWhiteSpace(string)
Checks if the string is null, empty, or consists only of white-space characters.
public static bool IsEmptyOrWhiteSpace(this string str)
Parameters
str
stringThe string to check.
Returns
- bool
True if the string is null, empty, or whitespace; otherwise, false.
IsEmptyOrWhiteSpace(string, string)
Returns default value if the string is null, empty, or whitespace; otherwise, returns the original string.
public static string IsEmptyOrWhiteSpace(this string str, string defaultValue)
Parameters
str
stringThe string to check.
defaultValue
stringThe value to return if string is null, empty, or whitespace.
Returns
- string
Default value or original string.
IsEqualTo(SecureString, SecureString)
Determines whether two secure strings are equal.
public static bool IsEqualTo(this SecureString value1, SecureString value2)
Parameters
value1
SecureStringThe first secure string.
value2
SecureStringThe second secure string.
Returns
- bool
true if both secure strings are equal; otherwise, false.
IsNumber(string, bool)
Determines whether the string represents a number.
public static bool IsNumber(this string s, bool floatPoint)
Parameters
s
stringThe string to test.
floatPoint
boolIf true, considers floating point numbers; otherwise, integers.
Returns
- bool
True if the string can be parsed as a number; otherwise, false.
IsNumberOnly(string, bool)
Determines whether the string contains only numeric characters (and optionally a decimal separator).
public static bool IsNumberOnly(this string s, bool floatPoint)
Parameters
Returns
- bool
True if the string contains only numbers; otherwise, false.
IsValidEmailAddress(string)
Determines whether the specified string is a valid email address.
public static bool IsValidEmailAddress(this string email)
Parameters
email
stringThe email address to test.
Returns
- bool
True if the email address is valid; otherwise, false.
IsValidUrl(string)
Determines whether the specified string is a valid URL.
public static bool IsValidUrl(this string url)
Parameters
url
stringThe URL to test.
Returns
- bool
True if the URL is valid; otherwise, false.
Join(IEnumerable<string>, string)
Joins the collection of strings using the specified separator.
public static string Join(this IEnumerable<string> parts, string separator)
Parameters
parts
IEnumerable<string>The collection of strings to join.
separator
stringThe separator string.
Returns
- string
A string resulting from the join.
JoinAnd(IEnumerable<string>)
Joins the collection of strings using the ampersand as the separator.
public static string JoinAnd(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinAt(IEnumerable<string>)
Joins the collection of strings using "@" as the separator.
public static string JoinAt(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinColon(IEnumerable<string>)
Joins the collection of strings using a colon as the separator.
public static string JoinColon(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinComma(IEnumerable<string>)
Joins the collection of strings using a comma as the separator.
public static string JoinComma(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinCommaSpace(IEnumerable<string>)
Joins the collection of strings using a comma and a space as the separator.
public static string JoinCommaSpace(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinDot(IEnumerable<string>)
Joins the collection of strings using a dot as the separator.
public static string JoinDot(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinDotComma(IEnumerable<string>)
Joins the collection of strings using a semicolon as the separator.
public static string JoinDotComma(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinEqual(IEnumerable<string>)
Joins the collection of strings using an equal sign as the separator.
public static string JoinEqual(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinN(IEnumerable<string>)
Joins the collection of strings using the newline character as the separator.
public static string JoinN(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinNL(IEnumerable<string>)
Joins the collection of strings using the system's newline as the separator.
public static string JoinNL(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinPipe(IEnumerable<string>)
Joins the collection of strings using the pipe character as the separator.
public static string JoinPipe(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinRN(IEnumerable<string>)
Joins the collection of strings using the carriage return and newline as the separator.
public static string JoinRN(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinSpace(IEnumerable<string>)
Joins the collection of strings using a space as the separator.
public static string JoinSpace(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
JoinTab(IEnumerable<string>)
Joins the collection of strings using a tab character as the separator.
public static string JoinTab(this IEnumerable<string> parts)
Parameters
parts
IEnumerable<string>The collection of strings to join.
Returns
- string
A string resulting from the join.
LastIndexOf(StringBuilder, char)
Finds the last index of a specified character in a StringBuilder.
public static int LastIndexOf(this StringBuilder builder, char value)
Parameters
builder
StringBuilderThe StringBuilder to search.
value
charThe character to locate.
Returns
- int
The zero-based index position of the character if found; otherwise, -1.
LastIndexOfIgnoreCase(string, string, int)
Searches for the last occurrence of a specified string, ignoring case.
public static int LastIndexOfIgnoreCase(this string str1, string str2, int index = -1)
Parameters
str1
stringThe string to search within.
str2
stringThe string to search for.
index
intThe starting position of the search. The search is conducted from this position to the beginning. Default is -1 (entire string).
Returns
- int
The index of the last occurrence of str2 in str1, or -1 if not found or if either string is null.
LightScreening(string)
Performs light screening on the input text by replacing spaces with hyphens and removing certain characters.
public static string LightScreening(this string text)
Parameters
text
stringThe input text.
Returns
- string
The screened text.
Like(string, string, bool)
Determines if the current string matches the specified pattern using SQL-like wildcards.
public static bool Like(this string toSearch, string toFind, bool ignoreCase = true)
Parameters
toSearch
stringThe string to search in.
toFind
stringThe pattern to search for. Use '_' for single character and '%' for multiple characters.
ignoreCase
boolif set to true, the comparison ignores case.
Returns
- bool
true if the string matches the pattern; otherwise, false.
Nl2Br(string)
Replaces newline characters in the string with HTML line breaks.
public static string Nl2Br(this string s)
Parameters
s
stringThe string to modify.
Returns
- string
The modified string with HTML <br /> tags in place of newlines.
Put(string, params object[])
Formats the string using standard string.Format with the provided arguments.
public static string Put(this string str, params object[] args)
Parameters
Returns
- string
A formatted string.
Exceptions
- ArgumentNullException
Thrown when args is null.
PutEx(string, params object[])
Formats the string using Smart.Format with the provided arguments.
public static string PutEx(this string str, params object[] args)
Parameters
Returns
- string
A formatted string.
Exceptions
- ArgumentNullException
Thrown when args is null.
PutExAsync(string, object[], CancellationToken)
Asynchronously formats the string using Smart.Format with the provided arguments.
public static ValueTask<string> PutExAsync(this string str, object[] args, CancellationToken cancellationToken)
Parameters
str
stringThe format string.
args
object[]The arguments to format the string with.
cancellationToken
CancellationTokenA token to cancel the asynchronous operation.
Returns
Exceptions
- ArgumentNullException
Thrown when args is null.
Reduce(string, int, string)
Reduces the string to a specified length and appends the specified ending.
public static string Reduce(this string s, int count, string endings)
Parameters
s
stringThe string to reduce.
count
intThe total length of the returned string including the ending.
endings
stringThe ending to append.
Returns
- string
A reduced version of the string.
Remove(string, string, bool)
Removes all occurrences of the specified substring from the string.
public static string Remove(this string s, string what, bool ignoreCase = false)
Parameters
s
stringThe string from which to remove.
what
stringThe substring to remove.
ignoreCase
boolIf true, performs a case-insensitive removal.
Returns
- string
The modified string.
RemoveDiacritics(string)
Removes diacritical marks from the string.
public static string RemoveDiacritics(this string s)
Parameters
s
stringThe string from which to remove diacritics.
Returns
- string
The modified string without accents.
RemoveLast(StringBuilder, int)
Removes the specified number of characters from the end of the StringBuilder.
public static void RemoveLast(this StringBuilder builder, int count)
Parameters
builder
StringBuilderThe StringBuilder to modify.
count
intThe number of characters to remove.
RemoveMultipleWhitespace(string)
Removes multiple consecutive whitespace characters from the specified text.
public static string RemoveMultipleWhitespace(this string text)
Parameters
text
stringThe input text.
Returns
- string
A string with multiple whitespaces replaced by a single space.
RemoveSpaces(string)
Removes all spaces from the string.
public static string RemoveSpaces(this string s)
Parameters
s
stringThe string from which to remove spaces.
Returns
- string
The string without spaces.
RemoveTrailingZeros(string)
Removes trailing zeros from the string using the current thread's number format decimal separator.
public static string RemoveTrailingZeros(this string s)
Parameters
s
stringThe input string.
Returns
- string
A string with trailing zeros removed.
RemoveTrailingZeros(string, string)
Removes trailing zeros from the string based on the specified separator.
public static string RemoveTrailingZeros(this string s, string separator)
Parameters
Returns
- string
A string with trailing zeros removed.
ReplaceIgnoreCase(string, string, string)
Replaces occurrences of a specified substring with another string, ignoring case.
public static string ReplaceIgnoreCase(this string original, string oldValue, string newValue)
Parameters
original
stringThe original string.
oldValue
stringThe substring to replace.
newValue
stringThe replacement string.
Returns
- string
The modified string.
ReplaceIgnoreCase(StringBuilder, string, string)
Replaces occurrences of a specified substring with another string in a StringBuilder, ignoring case.
public static StringBuilder ReplaceIgnoreCase(this StringBuilder builder, string oldValue, string newValue)
Parameters
builder
StringBuilderThe StringBuilder to modify.
oldValue
stringThe substring to replace.
newValue
stringThe replacement string.
Returns
- StringBuilder
The modified StringBuilder.
ReplaceWhiteSpaces(string)
Replaces all white space characters in the string with a single space.
public static string ReplaceWhiteSpaces(this string s)
Parameters
s
stringThe string in which to replace white spaces.
Returns
- string
The modified string.
ReplaceWhiteSpaces(string, char)
Replaces all white space characters in the string with the specified character.
public static string ReplaceWhiteSpaces(this string s, char c)
Parameters
s
stringThe string in which to replace white spaces.
c
charThe character to replace white spaces with.
Returns
- string
The modified string.
Reverse(string)
Reverses the specified string.
public static string Reverse(this string input)
Parameters
input
stringThe string to reverse.
Returns
- string
The reversed string.
Secure(string)
Converts the string to a SecureString.
public static SecureString Secure(this string str)
Parameters
str
stringThe input string.
Returns
- SecureString
The SecureString equivalent of the input string.
Split(string, string, bool)
Splits the string by the specified separator.
[Obsolete("Use SplitBySep method.")]
public static string[] Split(this string str, string separator, bool removeEmptyEntries = true)
Parameters
str
stringThe string to split.
separator
stringThe separator string.
removeEmptyEntries
boolIf true, removes empty entries.
Returns
- string[]
An array of substrings.
SplitByAt(string, bool)
Splits the string using the "@" symbol as the separator.
public static string[] SplitByAt(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitByColon(string, bool)
Splits the string using a colon as the separator.
public static string[] SplitByColon(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitByComma(string, bool)
Splits the string using a comma as the separator.
public static string[] SplitByComma(this string str, bool removeEmptyEntries = false)
Parameters
Returns
- string[]
An array of substrings.
SplitByDot(string, bool)
Splits the string using a dot as the separator.
public static string[] SplitByDot(this string str, bool removeEmptyEntries = false)
Parameters
Returns
- string[]
An array of substrings.
SplitByDotComma(string, bool)
Splits the string using a semicolon as the separator.
public static string[] SplitByDotComma(this string str, bool removeEmptyEntries = false)
Parameters
Returns
- string[]
An array of substrings.
SplitByEqual(string, bool)
Splits the string using the equal sign as the separator.
public static string[] SplitByEqual(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitByLength(string, int)
Splits the specified string into substrings of the given length.
public static IEnumerable<string> SplitByLength(this string stringToSplit, int length)
Parameters
Returns
- IEnumerable<string>
An enumerable collection of substrings.
SplitByLine(string, bool)
Splits the string using newline as the separator.
[Obsolete("Use SplitByN methods.")]
public static string[] SplitByLine(this string str, bool removeEmptyEntries = false)
Parameters
Returns
- string[]
An array of substrings.
SplitByLineSeps(string, bool)
Splits the string by line separators (RN, R, or N).
public static string[] SplitByLineSeps(this string str, bool removeEmptyEntries = true)
Parameters
str
stringThe string to split.
removeEmptyEntries
boolIf true, removes empty entries from the result.
Returns
- string[]
An array of substrings.
SplitByN(string, bool)
Splits the string using the newline character as the separator.
public static string[] SplitByN(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitByR(string, bool)
Splits the string using the carriage return as the separator.
public static string[] SplitByR(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitByRN(string, bool)
Splits the string using the carriage return and newline as the separator.
public static string[] SplitByRN(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitBySep(string, string, bool)
Splits the string by the specified separator.
public static string[] SplitBySep(this string str, string separator, bool removeEmptyEntries = true)
Parameters
str
stringThe string to split.
separator
stringThe separator string.
removeEmptyEntries
boolIf true, removes empty entries.
Returns
- string[]
An array of substrings.
SplitBySpace(string, bool)
Splits the string using a space as the separator.
public static string[] SplitBySpace(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitByTab(string, bool)
Splits the string using a tab character as the separator.
public static string[] SplitByTab(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
SplitLines(string, bool)
Splits the string by Environment.NewLine.
[Obsolete("Use SplitByRN or SplitByN methods.")]
public static string[] SplitLines(this string str, bool removeEmptyEntries = true)
Parameters
Returns
- string[]
An array of substrings.
StartsWithIgnoreCase(string, string)
Determines whether the string starts with the specified substring, ignoring case.
public static bool StartsWithIgnoreCase(this string str1, string str2)
Parameters
Returns
- bool
True if str1 starts with str2 ignoring case; otherwise, false.
StripBrackets(string, string, string)
Removes the enclosing brackets from the string if present.
public static string StripBrackets(this string str, string sStart, string sEnd)
Parameters
str
stringThe input string.
sStart
stringThe starting bracket string.
sEnd
stringThe ending bracket string.
Returns
- string
The string with brackets removed, if they were present.
ThrowIfEmpty(SecureString, string)
Throws an ArgumentNullException if the secure string is empty.
public static SecureString ThrowIfEmpty(this SecureString str, string paramName)
Parameters
str
SecureStringThe secure string.
paramName
stringThe name of the parameter.
Returns
- SecureString
The original secure string if not empty.
ThrowIfEmpty(string, string)
Throws ArgumentNullException if the string is null or empty.
public static string ThrowIfEmpty(this string str, string paramName)
Parameters
Returns
- string
The original string if not empty.
Exceptions
- ArgumentNullException
Thrown when string is null or empty.
Times(string, int)
Repeats the string a specified number of times.
public static string Times(this string value, int n)
Parameters
Returns
- string
A new string containing the original string repeated n times.
Times(string, int, string)
Repeats the string a specified number of times with a separator between each repetition.
public static string Times(this string value, int n, string separator)
Parameters
value
stringThe string to repeat.
n
intThe number of times to repeat the string.
separator
stringThe string to use as a separator between repetitions.
Returns
- string
A new string containing the original string repeated n times with the specified separator.
Exceptions
- ArgumentNullException
Thrown when value is null.
- ArgumentOutOfRangeException
Thrown when n is less than 1.
ToBitString(ArraySegment<byte>, char)
Converts an ArraySegment of bytes to its bit string representation with a specified separator.
public static string ToBitString(this ArraySegment<byte> buffer, char separator = ' ')
Parameters
buffer
ArraySegment<byte>The byte array segment.
separator
charThe character separator between byte bits.
Returns
- string
A string representing the bits of the bytes.
ToBitString(byte[], int?, int?, char)
Converts a byte array to its bit string representation with a specified separator.
public static string ToBitString(this byte[] buffer, int? index = null, int? count = null, char separator = ' ')
Parameters
buffer
byte[]The byte array.
index
int?Optional start index for conversion.
count
int?Optional count of bytes to convert.
separator
charThe character separator between byte bits.
Returns
- string
A string representing the bits of the bytes.
ToByteArray(string, char)
Converts a bit string representation to a byte array.
public static byte[] ToByteArray(this string bitString, char separator = ' ')
Parameters
bitString
stringThe string containing bits.
separator
charThe character that separates individual byte bits.
Returns
- byte[]
A byte array created from the bit string.
ToId(SecureString)
Converts a SecureString key to a numeric identifier.
public static int? ToId(this SecureString key)
Parameters
key
SecureStringThe secure key.
Returns
- int?
A numeric identifier or null if the key is null.
ToLatin(string)
Transliterates the Russian title to Latin characters.
public static string ToLatin(this string russianTitle)
Parameters
russianTitle
stringThe Russian string.
Returns
- string
The transliterated string in Latin.
ToLower(char, bool)
Converts the specified character to lowercase.
public static char ToLower(this char c, bool invariant = true)
Parameters
c
charThe character to convert.
invariant
boolIf set to true, uses culture-invariant conversion; otherwise, uses current culture.
Returns
- char
The lowercase equivalent of the character.
ToString(char[], int, int)
Converts a character array to a string using the specified count and starting index.
public static string ToString(this char[] arr, int count, int index = 0)
Parameters
arr
char[]The character array.
count
intThe number of characters to convert.
index
intThe starting index in the array.
Returns
- string
A new string constructed from the array.
ToString(char[], uint, int)
Converts a character array to a string using the specified count and starting index.
[CLSCompliant(false)]
public static string ToString(this char[] arr, uint count, int index = 0)
Parameters
arr
char[]The character array.
count
uintThe number of characters to convert.
index
intThe starting index in the array.
Returns
- string
A new string constructed from the array.
ToTitleCase(string)
Converts the string to title case using the current culture.
public static string ToTitleCase(this string value)
Parameters
value
stringThe string to convert.
Returns
- string
The string converted to title case.
ToUpper(char, bool)
Converts the specified character to uppercase.
public static char ToUpper(this char c, bool invariant = true)
Parameters
c
charThe character to convert.
invariant
boolIf set to true, uses culture-invariant conversion; otherwise, uses current culture.
Returns
- char
The uppercase equivalent of the character.
Trim(string, int)
Trims the string to the specified maximum length and appends "..." if it exceeds that length.
public static string Trim(this string value, int maxLength)
Parameters
Returns
- string
A trimmed version of the string.
TrimEnd(string, string)
Trims the specified end value from the end of the string if present.
public static string TrimEnd(this string str, string sEndValue)
Parameters
Returns
- string
The trimmed string.
TrimStart(string, string)
Trims the specified start value from the beginning of the string if present.
public static string TrimStart(this string str, string sStartValue)
Parameters
Returns
- string
The trimmed string.
Truncate(string, int)
Truncates the string to a specified length and appends "..." if truncated.
public static string Truncate(this string text, int maxLength)
Parameters
Returns
- string
The truncated string.
Truncate(string, int, string)
Truncates the string to a specified length and appends a custom suffix if truncated.
public static string Truncate(this string text, int maxLength, string suffix)
Parameters
text
stringThe string to truncate.
maxLength
intThe maximum length of the resulting string before adding the suffix.
suffix
stringThe string to append if truncation occurs.
Returns
- string
The truncated string with the suffix if truncation occurred.
Exceptions
- ArgumentOutOfRangeException
Thrown when maxLength is negative.
TruncateMiddle(string, int)
Truncates a string in the middle, preserving the start and end portions while adding an ellipsis in between.
public static string TruncateMiddle(this string input, int limit)
Parameters
input
stringThe string to truncate.
limit
intThe maximum length of the resulting string including the ellipsis.
Returns
- string
The truncated string with ellipsis in the middle if truncation was necessary, otherwise the original string.
TryToLong(string)
Tries to parse the string to a long integer.
public static long? TryToLong(this string str)
Parameters
str
stringThe string to parse.
Returns
- long?
The long value if successfully parsed; otherwise, null.
UTF8(ArraySegment<byte>)
Gets the string from an ArraySegment using UTF8 encoding.
public static string UTF8(this ArraySegment<byte> v)
Parameters
v
ArraySegment<byte>The ArraySegment of bytes.
Returns
- string
The decoded string.
UTF8(byte[])
Gets the string from a byte array using UTF8 encoding.
public static string UTF8(this byte[] v)
Parameters
v
byte[]The byte array.
Returns
- string
The UTF8 decoded string.
UTF8(byte[], int, int)
Gets the string from a portion of the byte array using UTF8 encoding.
public static string UTF8(this byte[] v, int index, int count)
Parameters
Returns
- string
The decoded string.
UTF8(byte[], uint, int)
Gets the string from a byte array using UTF8 encoding with a specified count.
[CLSCompliant(false)]
public static string UTF8(this byte[] v, uint count, int index = 0)
Parameters
Returns
- string
The decoded string.
UTF8(string)
Gets the UTF8 encoded bytes for the string.
public static byte[] UTF8(this string v)
Parameters
v
stringThe input string.
Returns
- byte[]
The UTF8 byte array.
UnSecure(SecureString)
Converts the SecureString to an unsecured string.
public static string UnSecure(this SecureString str)
Parameters
str
SecureStringThe SecureString.
Returns
- string
The unsecured string equivalent.
Unicode(ArraySegment<byte>)
Gets the string from an ArraySegment using Unicode encoding.
public static string Unicode(this ArraySegment<byte> v)
Parameters
v
ArraySegment<byte>The ArraySegment of bytes.
Returns
- string
The decoded string.
Unicode(byte[])
Gets the string from a byte array using Unicode encoding.
public static string Unicode(this byte[] v)
Parameters
v
byte[]The byte array.
Returns
- string
The Unicode decoded string.
Unicode(byte[], int, int)
Gets the string from a portion of the byte array using Unicode encoding.
public static string Unicode(this byte[] v, int index, int count)
Parameters
Returns
- string
The decoded string.
Unicode(byte[], uint, int)
Gets the string from a byte array using Unicode encoding with a specified count.
[CLSCompliant(false)]
public static string Unicode(this byte[] v, uint count, int index = 0)
Parameters
Returns
- string
The decoded string.
Unicode(string)
Gets the Unicode encoded bytes for the string.
public static byte[] Unicode(this string v)
Parameters
v
stringThe input string.
Returns
- byte[]
The Unicode byte array.
UrlEscape(string)
Escapes a URL string.
[Obsolete]
public static string UrlEscape(this string url)
Parameters
url
stringThe URL to escape.
Returns
- string
An escaped URL string.