StringHelper

Ecng.Common

Provides helper methods for string operations.

Eigenschaften

WindowsCyrillic
public static Encoding WindowsCyrillic { get; }
value = StringHelper.WindowsCyrillic

Gets the Windows Cyrillic encoding (code page 1251).

Methoden

AddDictionarySourceEx
public static SmartFormatter AddDictionarySourceEx(SmartFormatter formatter)
result = StringHelper.AddDictionarySourceEx(formatter)

Adds DictionarySourceEx to the formatter. Handles IDictionary with any key type (enum, int, etc.) and returns null for missing keys instead of throwing.

ASCII
public static string ASCII(ReadOnlySpan<byte> v)
result = StringHelper.ASCII(v)

Gets the string from a span of bytes using ASCII encoding.

v
The span of bytes.

Rückgabe: The ASCII decoded string.

ASCII
public static string ASCII(byte[] v)
result = StringHelper.ASCII(v)

Gets the string from a byte array using ASCII encoding.

v
The byte array.

Rückgabe: The ASCII decoded string.

ASCII
public static string ASCII(byte[] v, int index, int count)
result = StringHelper.ASCII(v, index, count)

Gets the string from a portion of the byte array using ASCII encoding.

v
The byte array.
index
The starting index.
count
The number of bytes to decode.

Rückgabe: The decoded string.

ASCII
public static string ASCII(byte[] v, uint count, int index)
result = StringHelper.ASCII(v, count, index)

Gets the string from a byte array using ASCII encoding with a specified count.

v
The byte array.
count
The number of bytes to decode.
index
The starting index.

Rückgabe: The decoded string.

ASCII
public static int ASCII(ReadOnlySpan<char> v, Span<byte> destination)
result = StringHelper.ASCII(v, destination)

Encodes a span of characters into a span of bytes using ASCII encoding.

v
The span of characters to encode.
destination
The destination span to write the encoded bytes.

Rückgabe: The number of bytes written to the destination.

ASCII
public static byte[] ASCII(string v)
result = StringHelper.ASCII(v)

Gets the ASCII encoded bytes for the string.

v
The input string.

Rückgabe: The ASCII byte array.

Base64
public static byte[] Base64(string value)
result = StringHelper.Base64(value)

Converts a base64 encoded string to a byte array.

value
The base64 encoded string.

Rückgabe: The byte array representation.

Base64
public static string Base64(byte[] value)
result = StringHelper.Base64(value)

Converts a byte array to a base64 encoded string.

value
The byte array.

Rückgabe: The base64 encoded string.

CheckBrackets
public static bool CheckBrackets(string str, string sStart, string sEnd)
result = StringHelper.CheckBrackets(str, sStart, sEnd)

Checks whether the string starts with the specified start string and ends with the specified end string.

str
The input string.
sStart
The starting string.
sEnd
The ending string.

Rückgabe: true if the string is enclosed by the specified brackets; otherwise, false.

ComparePaths
public static bool ComparePaths(string path1, string path2)
result = StringHelper.ComparePaths(path1, path2)

Compares two file paths for equality after normalizing them.

path1
The first file path.
path2
The second file path.

Rückgabe: true if the paths are equal; otherwise, false.

ContainsIgnoreCase
public static bool ContainsIgnoreCase(string str1, string str2)
result = StringHelper.ContainsIgnoreCase(str1, str2)

Determines whether the first string contains the second string, ignoring case.

str1
The string to search.
str2
The string to locate.

Rückgabe: True if str1 contains str2 when ignoring case; otherwise, false.

CreateSmartFormatterEx
public static SmartFormatter CreateSmartFormatterEx()
result = StringHelper.CreateSmartFormatterEx()

Creates a pre-configured SmartFormatter with DictionarySourceEx and DefaultFormatter.Name = "default".

Cyrillic
public static string Cyrillic(byte[] v)
result = StringHelper.Cyrillic(v)

Gets the string from a byte array using Windows Cyrillic encoding.

v
The byte array.

Rückgabe: The decoded string.

Cyrillic
public static string Cyrillic(byte[] v, int index, int count)
result = StringHelper.Cyrillic(v, index, count)

Gets the string from a portion of the byte array using Windows Cyrillic encoding.

v
The byte array.
index
The starting index.
count
The number of bytes to decode.

Rückgabe: The decoded string.

Cyrillic
public static string Cyrillic(byte[] v, uint count, int index)
result = StringHelper.Cyrillic(v, count, index)

Gets the string from a byte array using Windows Cyrillic encoding with a specified count.

v
The byte array.
count
The number of bytes to decode.
index
The starting index.

Rückgabe: The decoded string.

Cyrillic
public static byte[] Cyrillic(string v)
result = StringHelper.Cyrillic(v)

Gets the Windows Cyrillic encoded bytes for the string.

v
The input string.

Rückgabe: The Windows Cyrillic byte array.

Cyrillic
public static string Cyrillic(ReadOnlySpan<byte> v)
result = StringHelper.Cyrillic(v)

Gets the string from a span of bytes using Windows Cyrillic encoding.

v
The span of bytes.

Rückgabe: The decoded string.

Cyrillic
public static int Cyrillic(ReadOnlySpan<char> v, Span<byte> destination)
result = StringHelper.Cyrillic(v, destination)

Encodes a span of characters into a span of bytes using Windows Cyrillic encoding.

v
The span of characters to encode.
destination
The destination span to write the encoded bytes.

Rückgabe: The number of bytes written to the destination.

DataEscape
public static string DataEscape(string url)
result = StringHelper.DataEscape(url)

Escapes URL data.

url
The URL data to escape.

Rückgabe: An escaped URL data string.

DataUnEscape
public static string DataUnEscape(string url)
result = StringHelper.DataUnEscape(url)

Unescapes URL data.

url
The URL data to unescape.

Rückgabe: An unescaped URL data string.

Default
public static string Default(byte[] v, int index, int count)
result = StringHelper.Default(v, index, count)

Gets the string from a portion of the byte array using the default encoding.

v
The byte array.
index
The starting index.
count
The number of bytes to decode.

Rückgabe: The decoded string.

Default
public static byte[] Default(string v)
result = StringHelper.Default(v)

Gets the default encoding bytes for the string.

v
The input string.

Rückgabe: The byte array in default encoding.

Default
public static string Default(ReadOnlySpan<byte> v)
result = StringHelper.Default(v)

Gets the string from a span of bytes using the default encoding.

v
The span of bytes.

Rückgabe: The decoded string.

Default
public static int Default(ReadOnlySpan<char> v, Span<byte> destination)
result = StringHelper.Default(v, destination)

Encodes a span of characters into a span of bytes using the default encoding.

v
The span of characters to encode.
destination
The destination span to write the encoded bytes.

Rückgabe: The number of bytes written to the destination.

Default
public static string Default(byte[] v)
result = StringHelper.Default(v)

Gets the string from a byte array using the default encoding.

v
The byte array.

Rückgabe: The string decoded from the byte array.

Default
public static string Default(byte[] v, uint count, int index)
result = StringHelper.Default(v, count, index)

Gets the string from a byte array using the default encoding with a specified count.

v
The byte array.
count
The number of bytes to decode.
index
The starting index.

Rückgabe: The decoded string.

Digest
public static string Digest(byte[] digest)
result = StringHelper.Digest(digest)

Converts the byte array digest to its hexadecimal string representation.

digest
The byte array digest.

Rückgabe: The hexadecimal string.

Digest
public static string Digest(byte[] digest, int? length, int index)
result = StringHelper.Digest(digest, length, index)

Converts a portion of the byte array digest to its hexadecimal string representation.

digest
The byte array digest.
length
The number of bytes to process.
index
The starting index in the array.

Rückgabe: The hexadecimal string.

Duplicates
public static IEnumerable<string> Duplicates(IEnumerable<string> items)
result = StringHelper.Duplicates(items)

Returns the duplicate strings from the provided collection, ignoring case.

items
The collection of strings.

Rückgabe: An enumerable collection of duplicate strings.

Duplicates
public static IEnumerable<string> Duplicates(IEnumerable<string> items, IEqualityComparer<string> comparer)
result = StringHelper.Duplicates(items, comparer)

Returns the duplicate strings from the provided collection using the specified comparer.

items
The collection of strings.
comparer
The string comparer to use for determining duplicates.

Rückgabe: An enumerable collection of duplicate strings.

EmailValidationRegex
private static Regex EmailValidationRegex()
result = StringHelper.EmailValidationRegex()
EndsWithIgnoreCase
public static bool EndsWithIgnoreCase(string str1, string str2)
result = StringHelper.EndsWithIgnoreCase(str1, str2)

Determines whether the string ends with the specified substring, ignoring case.

str1
The string to test.
str2
The substring to compare.

Rückgabe: True if str1 ends with str2 ignoring case; otherwise, false.

EqualsIgnoreCase
public static bool EqualsIgnoreCase(string str1, string str2)
result = StringHelper.EqualsIgnoreCase(str1, str2)

Determines whether two strings are equal, ignoring case.

str1
The first string to compare.
str2
The second string to compare.

Rückgabe: True if the strings are equal ignoring case; otherwise, false.

FastIndexOf
public static int FastIndexOf(string source, string pattern)
result = StringHelper.FastIndexOf(source, pattern)

Searches for the specified pattern in the source string and returns the zero-based index of its first occurrence.

source
The source string to search.
pattern
The pattern to locate.

Rückgabe: The index of the first occurrence; otherwise, -1 if not found.

GetAndClear
public static string GetAndClear(StringBuilder builder)
result = StringHelper.GetAndClear(builder)

Retrieves the content of the StringBuilder and then clears it.

builder
The StringBuilder.

Rückgabe: The content of the StringBuilder before it was cleared.

GetDeterministicHashCode
public static int GetDeterministicHashCode(string value)
result = StringHelper.GetDeterministicHashCode(value)

Calculates a deterministic hash code for the specified string.

value
The string to hash.

Rückgabe: An integer hash code computed deterministically.

GetLangCode
public static string GetLangCode(string cultureName)
result = StringHelper.GetLangCode(cultureName)

Gets the two-letter ISO language code from the provided culture name.

cultureName
The culture name.

Rückgabe: The two-letter ISO language code.

Hex
public static string Hex(byte[] v)
result = StringHelper.Hex(v)

Gets the string from a byte array using hexadecimal encoding.

v
The byte array.

Rückgabe: The hexadecimal decoded string.

Hex
public static string Hex(byte[] v, int index, int count)
result = StringHelper.Hex(v, index, count)

Gets the string from a portion of the byte array using hexadecimal encoding.

v
The byte array.
index
The starting index.
count
The number of bytes to decode.

Rückgabe: The decoded hexadecimal string.

Hex
public static string Hex(byte[] v, uint count, int index)
result = StringHelper.Hex(v, count, index)

Gets the string from a byte array using hexadecimal encoding with a specified count.

v
The byte array.
count
The number of bytes to decode.
index
The starting index.

Rückgabe: The decoded hexadecimal string.

Hex
public static byte[] Hex(string v)
result = StringHelper.Hex(v)

Gets the hexadecimal encoded bytes for the string.

v
The input string.

Rückgabe: The hexadecimal byte array.

IndexOfIgnoreCase
public static int IndexOfIgnoreCase(string str1, string str2, int index)
result = StringHelper.IndexOfIgnoreCase(str1, str2, index)

Returns the zero-based index of the first occurrence of the specified substring, ignoring case.

str1
The string to search.
str2
The substring to locate.
index
The starting index for the search. Defaults to -1 for beginning.

Rückgabe: The index of the first occurrence, or -1 if not found.

Intern
public static string Intern(string str)
result = StringHelper.Intern(str)

Interns the specified string.

str
The string to intern.

Rückgabe: The interned string.

IsDigit
public static bool IsDigit(char c)
result = StringHelper.IsDigit(c)

Determines whether the specified character is a digit.

c
The character to test.

Rückgabe: True if the character is a digit; otherwise, false.

IsEmpty
public static string IsEmpty(string str, string defaultValue)
result = StringHelper.IsEmpty(str, defaultValue)

Returns default value if the string is null or empty; otherwise, returns the original string.

str
The string to check.
defaultValue
The value to return if string is null or empty.

Rückgabe: Default value or original string.

IsEmpty
public static bool IsEmpty(string str)
result = StringHelper.IsEmpty(str)

Checks if the string is null or empty.

str
The string to check.

Rückgabe: True if the string is null or empty; otherwise, false.

IsEmpty
public static bool IsEmpty(SecureString secureString)
result = StringHelper.IsEmpty(secureString)

Determines whether the specified secure string is empty.

secureString
The secure string to check.

Rückgabe: true if the secure string is null or empty; otherwise, false.

IsEmpty
public static bool IsEmpty(StringBuilder builder)
result = StringHelper.IsEmpty(builder)

Determines whether the StringBuilder is empty.

builder
The StringBuilder to evaluate.

Rückgabe: True if the StringBuilder is empty; otherwise, false.

IsEmptyOrWhiteSpace
public static bool IsEmptyOrWhiteSpace(string str)
result = StringHelper.IsEmptyOrWhiteSpace(str)

Checks if the string is null, empty, or consists only of white-space characters.

str
The string to check.

Rückgabe: True if the string is null, empty, or whitespace; otherwise, false.

IsEmptyOrWhiteSpace
public static string IsEmptyOrWhiteSpace(string str, string defaultValue)
result = StringHelper.IsEmptyOrWhiteSpace(str, defaultValue)

Returns default value if the string is null, empty, or whitespace; otherwise, returns the original string.

str
The string to check.
defaultValue
The value to return if string is null, empty, or whitespace.

Rückgabe: Default value or original string.

IsEqualTo
public static bool IsEqualTo(SecureString value1, SecureString value2)
result = StringHelper.IsEqualTo(value1, value2)

Determines whether two secure strings are equal.

value1
The first secure string.
value2
The second secure string.

Rückgabe: true if both secure strings are equal; otherwise, false.

IsNumber
public static bool IsNumber(string s, bool floatPoint)
result = StringHelper.IsNumber(s, floatPoint)

Determines whether the string represents a number.

s
The string to test.
floatPoint
If true, considers floating point numbers; otherwise, integers.

Rückgabe: True if the string can be parsed as a number; otherwise, false.

IsNumberOnly
public static bool IsNumberOnly(string s, bool floatPoint)
result = StringHelper.IsNumberOnly(s, floatPoint)

Determines whether the string contains only numeric characters (and optionally a decimal separator).

s
The string to test.
floatPoint
If true, allows decimal points or commas.

Rückgabe: True if the string contains only numbers; otherwise, false.

IsValidEmailAddress
public static bool IsValidEmailAddress(string email)
result = StringHelper.IsValidEmailAddress(email)

Determines whether the specified string is a valid email address.

email
The email address to test.

Rückgabe: True if the email address is valid; otherwise, false.

IsValidUrl
public static bool IsValidUrl(string url)
result = StringHelper.IsValidUrl(url)

Determines whether the specified string is a valid URL.

url
The URL to test.

Rückgabe: True if the URL is valid; otherwise, false.

Join
public static string Join(IEnumerable<string> parts, string separator)
result = StringHelper.Join(parts, separator)

Joins the collection of strings using the specified separator.

parts
The collection of strings to join.
separator
The separator string.

Rückgabe: A string resulting from the join.

JoinAnd
public static string JoinAnd(IEnumerable<string> parts)
result = StringHelper.JoinAnd(parts)

Joins the collection of strings using the ampersand as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinAt
public static string JoinAt(IEnumerable<string> parts)
result = StringHelper.JoinAt(parts)

Joins the collection of strings using "@" as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinColon
public static string JoinColon(IEnumerable<string> parts)
result = StringHelper.JoinColon(parts)

Joins the collection of strings using a colon as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinComma
public static string JoinComma(IEnumerable<string> parts)
result = StringHelper.JoinComma(parts)

Joins the collection of strings using a comma as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinCommaSpace
public static string JoinCommaSpace(IEnumerable<string> parts)
result = StringHelper.JoinCommaSpace(parts)

Joins the collection of strings using a comma and a space as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinDot
public static string JoinDot(IEnumerable<string> parts)
result = StringHelper.JoinDot(parts)

Joins the collection of strings using a dot as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinDotComma
public static string JoinDotComma(IEnumerable<string> parts)
result = StringHelper.JoinDotComma(parts)

Joins the collection of strings using a semicolon as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinEqual
public static string JoinEqual(IEnumerable<string> parts)
result = StringHelper.JoinEqual(parts)

Joins the collection of strings using an equal sign as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinN
public static string JoinN(IEnumerable<string> parts)
result = StringHelper.JoinN(parts)

Joins the collection of strings using the newline character as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinNL
public static string JoinNL(IEnumerable<string> parts)
result = StringHelper.JoinNL(parts)

Joins the collection of strings using the system's newline as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinPipe
public static string JoinPipe(IEnumerable<string> parts)
result = StringHelper.JoinPipe(parts)

Joins the collection of strings using the pipe character as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinRN
public static string JoinRN(IEnumerable<string> parts)
result = StringHelper.JoinRN(parts)

Joins the collection of strings using the carriage return and newline as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinSpace
public static string JoinSpace(IEnumerable<string> parts)
result = StringHelper.JoinSpace(parts)

Joins the collection of strings using a space as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

JoinTab
public static string JoinTab(IEnumerable<string> parts)
result = StringHelper.JoinTab(parts)

Joins the collection of strings using a tab character as the separator.

parts
The collection of strings to join.

Rückgabe: A string resulting from the join.

LastIndexOf
public static int LastIndexOf(StringBuilder builder, char value)
result = StringHelper.LastIndexOf(builder, value)

Finds the last index of a specified character in a StringBuilder.

builder
The StringBuilder to search.
value
The character to locate.

Rückgabe: The zero-based index position of the character if found; otherwise, -1.

LastIndexOfIgnoreCase
public static int LastIndexOfIgnoreCase(string str1, string str2, int index)
result = StringHelper.LastIndexOfIgnoreCase(str1, str2, index)

Searches for the last occurrence of a specified string, ignoring case.

str1
The string to search within.
str2
The string to search for.
index
The starting position of the search. The search is conducted from this position to the beginning. Default is -1 (entire string).

Rückgabe: The index of the last occurrence of str2 in str1, or -1 if not found or if either string is null.

LightScreening
public static string LightScreening(string text)
result = StringHelper.LightScreening(text)

Performs light screening on the input text by replacing spaces with hyphens and removing certain characters.

text
The input text.

Rückgabe: The screened text.

Like
public static bool Like(string toSearch, string toFind, bool ignoreCase)
result = StringHelper.Like(toSearch, toFind, ignoreCase)

Determines if the current string matches the specified pattern using SQL-like wildcards.

toSearch
The string to search in.
toFind
The pattern to search for. Use '_' for single character and '%' for multiple characters.
ignoreCase
if set to true, the comparison ignores case.

Rückgabe: true if the string matches the pattern; otherwise, false.

LikeEscapeRegex
private static Regex LikeEscapeRegex()
result = StringHelper.LikeEscapeRegex()
Nl2Br
public static string Nl2Br(string s)
result = StringHelper.Nl2Br(s)

Replaces newline characters in the string with HTML line breaks.

s
The string to modify.

Rückgabe: The modified string with HTML <br /> tags in place of newlines.

Put
public static string Put(string str, object[] args)
result = StringHelper.Put(str, args)

Formats the string using standard string.Format with the provided arguments.

str
The format string.
args
The arguments to format the string with.

Rückgabe: A formatted string.

PutEx
public static string PutEx(string str, object[] args)
result = StringHelper.PutEx(str, args)

Formats the string using Smart.Format with the provided arguments.

str
The format string.
args
The arguments to format the string with.

Rückgabe: A formatted string.

ReadOnly
public static SecureString ReadOnly(SecureString str)
result = StringHelper.ReadOnly(str)

Makes the SecureString read-only.

str
The SecureString.

Rückgabe: The read-only SecureString.

Reduce
public static string Reduce(string s, int count, string endings)
result = StringHelper.Reduce(s, count, endings)

Reduces the string to a specified length and appends the specified ending.

s
The string to reduce.
count
The total length of the returned string including the ending.
endings
The ending to append.

Rückgabe: A reduced version of the string.

Remove
public static string Remove(string s, string what, bool ignoreCase)
result = StringHelper.Remove(s, what, ignoreCase)

Removes all occurrences of the specified substring from the string.

s
The string from which to remove.
what
The substring to remove.
ignoreCase
If true, performs a case-insensitive removal.

Rückgabe: The modified string.

RemoveDiacritics
public static string RemoveDiacritics(string s)
result = StringHelper.RemoveDiacritics(s)

Removes diacritical marks from the string.

s
The string from which to remove diacritics.

Rückgabe: The modified string without accents.

RemoveLast
public static void RemoveLast(StringBuilder builder, int count)
StringHelper.RemoveLast(builder, count)

Removes the specified number of characters from the end of the StringBuilder.

builder
The StringBuilder to modify.
count
The number of characters to remove.
RemoveMultipleWhitespace
public static string RemoveMultipleWhitespace(string text)
result = StringHelper.RemoveMultipleWhitespace(text)

Removes multiple consecutive whitespace characters from the specified text.

text
The input text.

Rückgabe: A string with multiple whitespaces replaced by a single space.

RemoveSpaces
public static string RemoveSpaces(string s)
result = StringHelper.RemoveSpaces(s)

Removes all spaces from the string.

s
The string from which to remove spaces.

Rückgabe: The string without spaces.

RemoveTrailingZeros
public static string RemoveTrailingZeros(string s, string separator)
result = StringHelper.RemoveTrailingZeros(s, separator)

Removes trailing zeros from the string based on the specified separator.

s
The input string.
separator
The separator to consider while removing zeros.

Rückgabe: A string with trailing zeros removed.

RemoveTrailingZeros
public static string RemoveTrailingZeros(string s)
result = StringHelper.RemoveTrailingZeros(s)

Removes trailing zeros from the string using the current thread's number format decimal separator.

s
The input string.

Rückgabe: A string with trailing zeros removed.

ReplaceIgnoreCase
public static string ReplaceIgnoreCase(string original, string oldValue, string newValue)
result = StringHelper.ReplaceIgnoreCase(original, oldValue, newValue)

Replaces occurrences of a specified substring with another string, ignoring case.

original
The original string.
oldValue
The substring to replace.
newValue
The replacement string.

Rückgabe: The modified string.

ReplaceIgnoreCase
public static StringBuilder ReplaceIgnoreCase(StringBuilder builder, string oldValue, string newValue)
result = StringHelper.ReplaceIgnoreCase(builder, oldValue, newValue)

Replaces occurrences of a specified substring with another string in a StringBuilder, ignoring case.

builder
The StringBuilder to modify.
oldValue
The substring to replace.
newValue
The replacement string.

Rückgabe: The modified StringBuilder.

ReplaceWhiteSpaces
public static string ReplaceWhiteSpaces(string s)
result = StringHelper.ReplaceWhiteSpaces(s)

Replaces all white space characters in the string with a single space.

s
The string in which to replace white spaces.

Rückgabe: The modified string.

ReplaceWhiteSpaces
public static string ReplaceWhiteSpaces(string s, char c)
result = StringHelper.ReplaceWhiteSpaces(s, c)

Replaces all white space characters in the string with the specified character.

s
The string in which to replace white spaces.
c
The character to replace white spaces with.

Rückgabe: The modified string.

Reverse
public static string Reverse(string input)
result = StringHelper.Reverse(input)

Reverses the specified string.

input
The string to reverse.

Rückgabe: The reversed string.

Secure
public static SecureString Secure(string str)
result = StringHelper.Secure(str)

Converts the string to a SecureString.

str
The input string.

Rückgabe: The SecureString equivalent of the input string.

SplitByAt
public static string[] SplitByAt(string str, bool removeEmptyEntries)
result = StringHelper.SplitByAt(str, removeEmptyEntries)

Splits the string using the "@" symbol as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByColon
public static string[] SplitByColon(string str, bool removeEmptyEntries)
result = StringHelper.SplitByColon(str, removeEmptyEntries)

Splits the string using a colon as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByComma
public static string[] SplitByComma(string str, bool removeEmptyEntries)
result = StringHelper.SplitByComma(str, removeEmptyEntries)

Splits the string using a comma as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByDot
public static string[] SplitByDot(string str, bool removeEmptyEntries)
result = StringHelper.SplitByDot(str, removeEmptyEntries)

Splits the string using a dot as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByDotComma
public static string[] SplitByDotComma(string str, bool removeEmptyEntries)
result = StringHelper.SplitByDotComma(str, removeEmptyEntries)

Splits the string using a semicolon as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByEqual
public static string[] SplitByEqual(string str, bool removeEmptyEntries)
result = StringHelper.SplitByEqual(str, removeEmptyEntries)

Splits the string using the equal sign as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByLength
public static IEnumerable<string> SplitByLength(string stringToSplit, int length)
result = StringHelper.SplitByLength(stringToSplit, length)

Splits the specified string into substrings of the given length.

stringToSplit
The string to split.
length
The maximum length of each substring.

Rückgabe: An enumerable collection of substrings.

SplitByLineSeps
public static string[] SplitByLineSeps(string str, bool removeEmptyEntries)
result = StringHelper.SplitByLineSeps(str, removeEmptyEntries)

Splits the string by line separators (RN, R, or N).

str
The string to split.
removeEmptyEntries
If true, removes empty entries from the result.

Rückgabe: An array of substrings.

SplitByN
public static string[] SplitByN(string str, bool removeEmptyEntries)
result = StringHelper.SplitByN(str, removeEmptyEntries)

Splits the string using the newline character as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByR
public static string[] SplitByR(string str, bool removeEmptyEntries)
result = StringHelper.SplitByR(str, removeEmptyEntries)

Splits the string using the carriage return as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByRN
public static string[] SplitByRN(string str, bool removeEmptyEntries)
result = StringHelper.SplitByRN(str, removeEmptyEntries)

Splits the string using the carriage return and newline as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitBySep
public static string[] SplitBySep(string str, string separator, bool removeEmptyEntries)
result = StringHelper.SplitBySep(str, separator, removeEmptyEntries)

Splits the string by the specified separator.

str
The string to split.
separator
The separator string.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitBySpace
public static string[] SplitBySpace(string str, bool removeEmptyEntries)
result = StringHelper.SplitBySpace(str, removeEmptyEntries)

Splits the string using a space as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

SplitByTab
public static string[] SplitByTab(string str, bool removeEmptyEntries)
result = StringHelper.SplitByTab(str, removeEmptyEntries)

Splits the string using a tab character as the separator.

str
The string to split.
removeEmptyEntries
If true, removes empty entries.

Rückgabe: An array of substrings.

StartsWithIgnoreCase
public static bool StartsWithIgnoreCase(string str1, string str2)
result = StringHelper.StartsWithIgnoreCase(str1, str2)

Determines whether the string starts with the specified substring, ignoring case.

str1
The string to test.
str2
The substring to compare.

Rückgabe: True if str1 starts with str2 ignoring case; otherwise, false.

StripBrackets
public static string StripBrackets(string str, string sStart, string sEnd)
result = StringHelper.StripBrackets(str, sStart, sEnd)

Removes the enclosing brackets from the string if present.

str
The input string.
sStart
The starting bracket string.
sEnd
The ending bracket string.

Rückgabe: The string with brackets removed, if they were present.

ThrowIfEmpty
public static string ThrowIfEmpty(string str, string paramName)
result = StringHelper.ThrowIfEmpty(str, paramName)

Throws ArgumentNullException if the string is null or empty.

str
The string to check.
paramName
The parameter name to use in the exception.

Rückgabe: The original string if not empty.

ThrowIfEmpty
public static SecureString ThrowIfEmpty(SecureString str, string paramName)
result = StringHelper.ThrowIfEmpty(str, paramName)

Throws an ArgumentNullException if the secure string is empty.

str
The secure string.
paramName
The name of the parameter.

Rückgabe: The original secure string if not empty.

Times
public static string Times(string value, int n, string separator)
result = StringHelper.Times(value, n, separator)

Repeats the string a specified number of times with a separator between each repetition.

value
The string to repeat.
n
The number of times to repeat the string.
separator
The string to use as a separator between repetitions.

Rückgabe: A new string containing the original string repeated n times with the specified separator.

Times
public static string Times(string value, int n)
result = StringHelper.Times(value, n)

Repeats the string a specified number of times.

value
The string to repeat.
n
The number of times to repeat the string.

Rückgabe: A new string containing the original string repeated n times.

ToBitString
public static string ToBitString(byte[] buffer, int? index, int? count, char separator)
result = StringHelper.ToBitString(buffer, index, count, separator)

Converts a byte array to its bit string representation with a specified separator.

buffer
The byte array.
index
Optional start index for conversion.
count
Optional count of bytes to convert.
separator
The character separator between byte bits.

Rückgabe: A string representing the bits of the bytes.

ToByteArray
public static byte[] ToByteArray(string bitString, char separator)
result = StringHelper.ToByteArray(bitString, separator)

Converts a bit string representation to a byte array.

bitString
The string containing bits.
separator
The character that separates individual byte bits.

Rückgabe: A byte array created from the bit string.

ToId
public static int? ToId(SecureString key)
result = StringHelper.ToId(key)

Converts a SecureString key to a numeric identifier.

key
The secure key.

Rückgabe: A numeric identifier or null if the key is null.

ToLatin
public static string ToLatin(string russianTitle)
result = StringHelper.ToLatin(russianTitle)

Transliterates the Russian title to Latin characters.

russianTitle
The Russian string.

Rückgabe: The transliterated string in Latin.

ToLower
public static char ToLower(char c, bool invariant)
result = StringHelper.ToLower(c, invariant)

Converts the specified character to lowercase.

c
The character to convert.
invariant
If set to true, uses culture-invariant conversion; otherwise, uses current culture.

Rückgabe: The lowercase equivalent of the character.

ToString
public static string ToString(char[] arr, int count, int index)
result = StringHelper.ToString(arr, count, index)

Converts a character array to a string using the specified count and starting index.

arr
The character array.
count
The number of characters to convert.
index
The starting index in the array.

Rückgabe: A new string constructed from the array.

ToString
public static string ToString(char[] arr, uint count, int index)
result = StringHelper.ToString(arr, count, index)

Converts a character array to a string using the specified count and starting index.

arr
The character array.
count
The number of characters to convert.
index
The starting index in the array.

Rückgabe: A new string constructed from the array.

ToTitleCase
public static string ToTitleCase(string value)
result = StringHelper.ToTitleCase(value)

Converts the string to title case using the current culture.

value
The string to convert.

Rückgabe: The string converted to title case.

ToUpper
public static char ToUpper(char c, bool invariant)
result = StringHelper.ToUpper(c, invariant)

Converts the specified character to uppercase.

c
The character to convert.
invariant
If set to true, uses culture-invariant conversion; otherwise, uses current culture.

Rückgabe: The uppercase equivalent of the character.

Trim
public static string Trim(string value, int maxLength)
result = StringHelper.Trim(value, maxLength)

Trims the string to the specified maximum length and appends "..." if it exceeds that length.

value
The string to trim.
maxLength
The maximum length of the returned string.

Rückgabe: A trimmed version of the string.

TrimEnd
public static string TrimEnd(string str, string sEndValue)
result = StringHelper.TrimEnd(str, sEndValue)

Trims the specified end value from the end of the string if present.

str
The input string.
sEndValue
The ending substring to remove.

Rückgabe: The trimmed string.

TrimStart
public static string TrimStart(string str, string sStartValue)
result = StringHelper.TrimStart(str, sStartValue)

Trims the specified start value from the beginning of the string if present.

str
The input string.
sStartValue
The starting substring to remove.

Rückgabe: The trimmed string.

Truncate
public static string Truncate(string text, int maxLength, string suffix)
result = StringHelper.Truncate(text, maxLength, suffix)

Truncates the string to a specified length and appends a custom suffix if truncated.

text
The string to truncate.
maxLength
The maximum length of the resulting string before adding the suffix.
suffix
The string to append if truncation occurs.

Rückgabe: The truncated string with the suffix if truncation occurred.

Truncate
public static string Truncate(string text, int maxLength)
result = StringHelper.Truncate(text, maxLength)

Truncates the string to a specified length and appends "..." if truncated.

text
The string to truncate.
maxLength
The maximum length of the resulting string.

Rückgabe: The truncated string.

TruncateMiddle
public static string TruncateMiddle(string input, int limit)
result = StringHelper.TruncateMiddle(input, limit)

Truncates a string in the middle, preserving the start and end portions while adding an ellipsis in between.

input
The string to truncate.
limit
The maximum length of the resulting string including the ellipsis.

Rückgabe: The truncated string with ellipsis in the middle if truncation was necessary, otherwise the original string.

TryToLong
public static long? TryToLong(string str)
result = StringHelper.TryToLong(str)

Tries to parse the string to a long integer.

str
The string to parse.

Rückgabe: The long value if successfully parsed; otherwise, null.

Unicode
public static string Unicode(byte[] v, int index, int count)
result = StringHelper.Unicode(v, index, count)

Gets the string from a portion of the byte array using Unicode encoding.

v
The byte array.
index
The starting index.
count
The number of bytes to decode.

Rückgabe: The decoded string.

Unicode
public static int Unicode(ReadOnlySpan<char> v, Span<byte> destination)
result = StringHelper.Unicode(v, destination)

Encodes a span of characters into a span of bytes using Unicode encoding.

v
The span of characters to encode.
destination
The destination span to write the encoded bytes.

Rückgabe: The number of bytes written to the destination.

Unicode
public static string Unicode(ReadOnlySpan<byte> v)
result = StringHelper.Unicode(v)

Gets the string from a span of bytes using Unicode encoding.

v
The span of bytes.

Rückgabe: The Unicode decoded string.

Unicode
public static byte[] Unicode(string v)
result = StringHelper.Unicode(v)

Gets the Unicode encoded bytes for the string.

v
The input string.

Rückgabe: The Unicode byte array.

Unicode
public static string Unicode(byte[] v)
result = StringHelper.Unicode(v)

Gets the string from a byte array using Unicode encoding.

v
The byte array.

Rückgabe: The Unicode decoded string.

Unicode
public static string Unicode(byte[] v, uint count, int index)
result = StringHelper.Unicode(v, count, index)

Gets the string from a byte array using Unicode encoding with a specified count.

v
The byte array.
count
The number of bytes to decode.
index
The starting index.

Rückgabe: The decoded string.

UnSecure
public static string UnSecure(SecureString str)
result = StringHelper.UnSecure(str)

Converts the SecureString to an unsecured string.

str
The SecureString.

Rückgabe: The unsecured string equivalent.

UrlValidationRegex
private static Regex UrlValidationRegex()
result = StringHelper.UrlValidationRegex()
UTF8
public static byte[] UTF8(string v)
result = StringHelper.UTF8(v)

Gets the UTF8 encoded bytes for the string.

v
The input string.

Rückgabe: The UTF8 byte array.

UTF8
public static string UTF8(byte[] v)
result = StringHelper.UTF8(v)

Gets the string from a byte array using UTF8 encoding.

v
The byte array.

Rückgabe: The UTF8 decoded string.

UTF8
public static string UTF8(byte[] v, int index, int count)
result = StringHelper.UTF8(v, index, count)

Gets the string from a portion of the byte array using UTF8 encoding.

v
The byte array.
index
The starting index.
count
The number of bytes to decode.

Rückgabe: The decoded string.

UTF8
public static string UTF8(byte[] v, uint count, int index)
result = StringHelper.UTF8(v, count, index)

Gets the string from a byte array using UTF8 encoding with a specified count.

v
The byte array.
count
The number of bytes to decode.
index
The starting index.

Rückgabe: The decoded string.

UTF8
public static int UTF8(ReadOnlySpan<char> v, Span<byte> destination)
result = StringHelper.UTF8(v, destination)

Encodes a span of characters into a span of bytes using UTF8 encoding.

v
The span of characters to encode.
destination
The destination span to write the encoded bytes.

Rückgabe: The number of bytes written to the destination.

UTF8
public static string UTF8(ReadOnlySpan<byte> v)
result = StringHelper.UTF8(v)

Gets the string from a span of bytes using UTF8 encoding.

v
The span of bytes.

Rückgabe: The UTF8 decoded string.

WhitespaceRegex
private static Regex WhitespaceRegex()
result = StringHelper.WhitespaceRegex()

Felder

HexEncoding
public static readonly HexEncoding HexEncoding
value = StringHelper.HexEncoding

Provides hexadecimal encoding functionality.

N
public const string N
value = StringHelper.N

Represents the newline character "\n".

R
public const string R
value = StringHelper.R

Represents the carriage return character "\r".

RN
public const string RN
value = StringHelper.RN

Represents the carriage return and newline characters "\r\n".