Class StringExtensions
- Namespace
- MADE.Data.Converters.Extensions
- Assembly
- MADE.Data.Converters.dll
Defines a collection of extensions for string values.
public static class StringExtensions
- Inheritance
-
StringExtensions
- Inherited Members
Methods
FromBase64(string, Encoding?)
Converts a Base64 string to a value using the specified encoding.
public static string FromBase64(this string base64Value, Encoding? encoding = null)
Parameters
base64ValuestringThe Base64 value to convert.
encodingEncodingThe encoding to get the value string while converting.
Returns
- string
The string value representing the Base64 string.
ToBase64(string, Encoding?)
Converts a value to a Base64 string using the specified encoding.
Default encoding is UTF-8.
public static string ToBase64(this string value, Encoding? encoding = null)
Parameters
valuestringThe string value to convert.
encodingEncodingThe encoding to get the value bytes while converting.
Returns
- string
The Base64 string representing the value.
ToBoolean(string)
Converts a string value to a boolean.
public static bool ToBoolean(this string value)
Parameters
valuestringThe value to convert.
Returns
- bool
The boolean representing the value.
ToDefaultCase(string)
Converts a value to default case using the case rules of the invariant culture.
public static string ToDefaultCase(this string value)
Parameters
valuestringThe value to convert.
Returns
- string
The converted default case string.
Examples
string converted = "HELLO, WORLD".ToDefaultCase(); // converted = "Hello, world".
ToDouble(string)
Converts a string value to a double.
public static double ToDouble(this string value)
Parameters
valuestringThe value to convert.
Returns
- double
The double representing the value.
ToFloat(string)
Converts a string value to a float.
public static float ToFloat(this string value)
Parameters
valuestringThe value to convert.
Returns
- float
The float representing the value.
ToInt(string)
Converts a string value to an integer.
public static int ToInt(this string value)
Parameters
valuestringThe value to convert.
Returns
- int
The int representing the value.
ToMemoryStreamAsync(string, CancellationToken)
Converts a string value to a MemoryStream.
public static Task<MemoryStream> ToMemoryStreamAsync(this string value, CancellationToken cancellationToken = default)
Parameters
valuestringThe value to convert.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<MemoryStream>
A MemoryStream representing the string value.
ToNullableDouble(string)
Converts a string value to a nullable double.
public static double? ToNullableDouble(this string value)
Parameters
valuestringThe value to convert.
Returns
- double?
The nullable double representing the value.
ToNullableFloat(string)
Converts a string value to a nullable float.
public static float? ToNullableFloat(this string value)
Parameters
valuestringThe value to convert.
Returns
- float?
The nullable float representing the value.
ToNullableInt(string)
Converts a string value to a nullable integer.
public static int? ToNullableInt(this string value)
Parameters
valuestringThe value to convert.
Returns
- int?
The nullable integer representing the value.
ToSlug(string)
Converts a string to a URL-friendly slug by removing diacritics, replacing non-alphanumeric characters with hyphens, and lowercasing.
public static string ToSlug(this string value)
Parameters
valuestringThe value to convert to a slug.
Returns
- string
A URL-friendly slug string.
ToTitleCase(string)
Converts a value to title case using the case rules of the invariant culture.
public static string ToTitleCase(this string value)
Parameters
valuestringThe value to convert.
Returns
- string
The converted title case string.
Examples
string converted = "HELLO, WORLD".ToTitleCase(); // converted = "Hello, World".
Truncate(string, int)
Truncates a string value to the specified length with an ellipsis.
public static string Truncate(this string value, int maxLength)
Parameters
Returns
- string
A truncated string with ellipsis if the value's length is greater than the
maxLength.