Aether Utilities Aether Utilities
Aether Utilities Aether Utilities
DocFX + Singulink = ♥

Search Results for

    Edit this page

    Class StringExtensions

    Namespace
    AetherUtils.Core.Extensions
    Assembly
    AetherUtils.Core.dll
    Provides extension methods for manipulating string objects.
    public static class StringExtensions
    Inheritance
    object
    StringExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()

    Methods

    BytesFromString(string)

    Get a byte array representing the string using UTF8.
    public static byte[] BytesFromString(this string value)

    Parameters

    value string
    A string to get the bytes of.

    Returns

    byte[]
    A byte array containing the bytes representing the string.

    BytesToEncodedBytes(byte[], HashEncoding)

    Encode the byte array to the specified HashEncoding.
    [UsedImplicitly]
    public static byte[] BytesToEncodedBytes(this byte[] bytes, HashEncoding encoding)

    Parameters

    bytes byte[]
    A byte array to encode.
    encoding HashEncoding
    The HashEncoding to use.

    Returns

    byte[]
    A byte array containing the encoded bytes.

    BytesToEncodedString(byte[], HashEncoding)

    Encode the byte array to the specified HashEncoding.
    [UsedImplicitly]
    public static string BytesToEncodedString(this byte[] bytes, HashEncoding encoding)

    Parameters

    bytes byte[]
    A byte array to encode.
    encoding HashEncoding
    The HashEncoding to use.

    Returns

    string
    A string encoded using the specified HashEncoding.

    CreateDragImage(string, Font)

    Creates a new Bitmap image from the specified text. This image can then be used for a drag-drop operation to show a preview of the data being dragged.
    [UsedImplicitly]
    public static Bitmap CreateDragImage(this string text, Font font)

    Parameters

    text string
    The text to capture as a Bitmap.
    font Font
    The font to draw the image string with.

    Returns

    Bitmap
    A new Bitmap "screenshot" of the text.

    DecodedBytesFromEncodedString(string, HashEncoding)

    Decodes the encoded string according to the specified HashEncoding.
    public static byte[] DecodedBytesFromEncodedString(this string value, HashEncoding encoding)

    Parameters

    value string
    The encoded string.
    encoding HashEncoding
    The HashEncoding to use.

    Returns

    byte[]
    A byte array containing the decoded bytes.

    DecodedStringFromEncodedString(string, HashEncoding)

    Decodes an encoded string according to the specified HashEncoding.
    [UsedImplicitly]
    public static string DecodedStringFromEncodedString(this string value, HashEncoding encoding)

    Parameters

    value string
    The encoded string.
    encoding HashEncoding
    The HashEncoding to use.

    Returns

    string
    A decoded string.

    DeserializeJson<T>(string)

    Deserializes an object from a JSON string.
    public static T? DeserializeJson<T>(this string json) where T : class

    Parameters

    json string
    The JSON string to deserialize.

    Returns

    T
    The deserialized object or null if the deserialization failed.

    Type Parameters

    T
    The type of object to deserialize to.

    Exceptions

    ArgumentException
    If json was null or empty.

    DeserializeXml<T>(string)

    Deserializes an object from an XML string.
    public static T? DeserializeXml<T>(this string xml) where T : class

    Parameters

    xml string
    The XML string to deserialize.

    Returns

    T
    The deserialized object or null if the deserialization failed.

    Type Parameters

    T
    The type of object to deserialize to.

    Exceptions

    ArgumentException
    If xml was null or empty.

    FromSecureString(SecureString)

    Convert a SecureString to an unsecured string.
    [UsedImplicitly]
    public static string FromSecureString(this SecureString secure)

    Parameters

    secure SecureString
    The SecureString.

    Returns

    string
    The unsecured string.

    Exceptions

    ArgumentNullException
    If secure was null.

    ImageFromString(string)

    Convert the Base64 representation of a picture into a usable Image object for drawing.
    [UsedImplicitly]
    public static Image ImageFromString(this string base64)

    Parameters

    base64 string
    The Image as a Base64 string.

    Returns

    Image
    An Image or null if base64 is an invalid string.

    Exceptions

    ArgumentNullException
    If base64 was null.
    FormatException
    If the input was not a valid Base64 string.

    IsBase64Encoded(string)

    Get a value indicating if the string appears to be Base64 encoded.
    public static bool IsBase64Encoded(this string input)

    Parameters

    input string
    The string to check encoding on.

    Returns

    bool
    true if the string is Base64 encoded; false otherwise.

    Exceptions

    ArgumentNullException
    If input was null.

    IsHexEncoded(string)

    Get a value indicating if the string appears to be Hex (Base16) encoded.
    [UsedImplicitly]
    public static bool IsHexEncoded(this string input)

    Parameters

    input string
    The string to check encoding on.

    Returns

    bool
    true if the string is Hex encoded; false otherwise.

    Exceptions

    ArgumentNullException
    If input was null.

    OpenUrl(string)

    Opens the specified URL in the default web browser.
    [UsedImplicitly]
    public static void OpenUrl(this string url)

    Parameters

    url string
    The URL to open.

    RemoveWhitespace(string)

    Removes all whitespace characters from the specified string.
    public static string RemoveWhitespace(this string str)

    Parameters

    str string
    The string to remove whitespace from.

    Returns

    string
    A new string, without the whitespace characters.

    StringToEncodedBytes(string, HashEncoding)

    Encode the string to the specified HashEncoding.
    [UsedImplicitly]
    public static byte[] StringToEncodedBytes(this string value, HashEncoding encoding)

    Parameters

    value string
    The string to encode.
    encoding HashEncoding
    The HashEncoding to use.

    Returns

    byte[]
    A byte array containing the encoded bytes.

    StringToEncodedString(string, HashEncoding)

    Encode the string to the specified HashEncoding.
    public static string StringToEncodedString(this string value, HashEncoding encoding)

    Parameters

    value string
    The string to encode.
    encoding HashEncoding
    The HashEncoding to use.

    Returns

    string
    A string encoded using the specified HashEncoding.

    ToSecureString(string)

    Convert an unsecure string value into a SecureString.
    [UsedImplicitly]
    public static SecureString ToSecureString(this string unsecure)

    Parameters

    unsecure string
    The unsecure string.

    Returns

    SecureString
    A new read-only SecureString.

    Exceptions

    ArgumentNullException
    If unsecure was null.

    Trim(string, int)

    Trims the string to be the length specified before a new-line character is inserted.

    If the new-line character was inserted at the position of a period (.), the new line is inserted at the index of (.) + 1. If the line being checked contains a new-line character already, nothing is done for that line.

    [UsedImplicitly]
    public static TrimmedString Trim(this string input, int lineLength = 80)

    Parameters

    input string
    The string to trim.
    lineLength int
    The number of characters in the line; default is 80.

    Returns

    TrimmedString
    A new TrimmedString containing the trimmed string and the number of new lines.

    Exceptions

    ArgumentNullException
    If input was null.
    (c) 2024 Ethan Hann. All rights reserved.