Wolfgang.Extensions.String
Search Results for

    Class StringExtensions

    A collection of extension methods for the string type.

    Inheritance
    object
    StringExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Wolfgang.Extensions.String
    Assembly: Wolfgang.Extensions.String.dll
    Syntax
    public static class StringExtensions

    Methods

    | Edit this page View Source

    Left(string?, int)

    Returns the left most specified character from the specified string.

    Declaration
    public static string? Left(this string? s, int length)
    Parameters
    Type Name Description
    string s

    The instance to retrieve from.

    int length

    The number of characters to retrieve.

    Returns
    Type Description
    string

    A string that is equivalent to the substring that begins at index 0 and is the specified number of characters long. If the string is null, null will be returned. If the string contains fewer than the specified number of characters then the entire string is returned.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    length is less than zero.

    | Edit this page View Source

    PadCenter(string?, int)

    Returns a new string of a specified length in which the current string is centered with spaces padding either side.

    Declaration
    public static string PadCenter(this string? s, int totalWidth)
    Parameters
    Type Name Description
    string s

    The string to center.

    int totalWidth

    The number of characters in the resulting string. If totalWidth is less than the length of s, the original string is returned unchanged.

    Returns
    Type Description
    string

    A new string that is equivalent to s, but center-aligned and padded on both sides with spaces. When the padding is uneven, the extra character is placed on the right.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    ArgumentOutOfRangeException

    totalWidth is less than zero.

    | Edit this page View Source

    PadCenter(string?, int, char)

    Returns a new string of a specified length in which the current string is centered with a specified character padding either side.

    Declaration
    public static string PadCenter(this string? s, int totalWidth, char paddingChar)
    Parameters
    Type Name Description
    string s

    The string to center.

    int totalWidth

    The number of characters in the resulting string. If totalWidth is less than the length of s, the original string is returned unchanged.

    char paddingChar

    A Unicode padding character.

    Returns
    Type Description
    string

    A new string that is equivalent to s, but center-aligned and padded on both sides with the paddingChar character. When the padding is uneven, the extra character is placed on the right.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    ArgumentOutOfRangeException

    totalWidth is less than zero.

    | Edit this page View Source

    Right(string?, int)

    Returns the right most specified character from the specified string.

    Declaration
    public static string? Right(this string? s, int length)
    Parameters
    Type Name Description
    string s

    The instance to retrieve from.

    int length

    The number of characters to retrieve.

    Returns
    Type Description
    string

    A string that is equivalent to the substring that begins the specified number of characters before the end and continues to the last character. If the string is null, null will be returned. If the string contains fewer than the specified number of characters then the entire string is returned.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    length is less than zero.

    | Edit this page View Source

    ToCamelCase(string)

    Converts a string to camelCase by lowering the first character, capitalizing the first letter of each subsequent word, and removing all separator characters.

    Declaration
    public static string ToCamelCase(this string s)
    Parameters
    Type Name Description
    string s

    The string to convert.

    Returns
    Type Description
    string

    The specified string in camel case.

    Remarks
        Original: " A sample string for processing! "
    Return value: aSampleStringForProcessing!

    Characters where IsSeparator(char) returns true are treated as word boundaries and removed from the output. Control characters and punctuation are preserved.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    | Edit this page View Source

    ToKebabCase(string)

    Converts all letters to lower case and replaces separator characters with dashes.

    Declaration
    public static string ToKebabCase(this string s)
    Parameters
    Type Name Description
    string s

    The string to convert.

    Returns
    Type Description
    string

    The specified string in kebab case.

    Remarks
        Original: "A sample string for processing!"
    Return value: a-sample-string-for-processing!

    Characters where IsSeparator(char) returns true are replaced with dashes. Control characters and punctuation are preserved.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    | Edit this page View Source

    ToPascalCase(string)

    Capitalizes each word, including the first one, and removes all separator characters.

    Declaration
    public static string ToPascalCase(this string s)
    Parameters
    Type Name Description
    string s

    The string to convert.

    Returns
    Type Description
    string

    The specified string in Pascal case.

    Remarks
        Original: " A sample string for processing! "
    Return value: ASampleStringForProcessing!

    Characters where IsSeparator(char) returns true are treated as word boundaries and removed from the output. Control characters and punctuation are preserved.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    | Edit this page View Source

    ToSnakeCase(string)

    Converts all letters to lower case and replaces separator characters with underscores.

    Declaration
    public static string ToSnakeCase(this string s)
    Parameters
    Type Name Description
    string s

    The string to convert.

    Returns
    Type Description
    string

    The specified string in snake case.

    Remarks
        Original: "A sample string for processing!"
    Return value: a_sample_string_for_processing!

    Characters where IsSeparator(char) returns true are replaced with underscores. Control characters and punctuation are preserved.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    | Edit this page View Source

    ToTitleCase(string)

    Capitalizes each word, leaving spaces and punctuation.

    Declaration
    public static string ToTitleCase(this string s)
    Parameters
    Type Name Description
    string s

    The string to convert.

    Returns
    Type Description
    string

    The specified string in title case.

    Remarks
        Original: "a sample string for processing!"
    Return value: A Sample String For Processing!

    Delegates to ToTitleCase(string) using CurrentCulture. Words that are entirely uppercase are left unchanged. This is a general-purpose implementation; proper names and addresses may require specialized handling.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    • Edit this page
    • View Source
    In this article
    Back to top Made with DocFX