Unosquare
    Show / Hide Table of Contents

    Class StringExtensions

    String related extension methods.

    Inheritance
    Object
    StringExtensions
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Swan
    Syntax
    public static class StringExtensions

    Methods

    Contains(String, Char[])

    Determines whether the specified String contains any of characters in the specified array of Char.

    Declaration
    public static bool Contains(this string value, params char[] chars)
    Parameters
    Type Name Description
    String value

    A String to test.

    Char[] chars

    An array of Char that contains characters to find.

    Returns
    Type Description
    Boolean

    true if value contains any of chars; otherwise, false.

    FormatBytes(Int64)

    Formats a long into the closest bytes string.

    Declaration
    public static string FormatBytes(this long bytes)
    Parameters
    Type Name Description
    Int64 bytes

    The bytes length.

    Returns
    Type Description
    String

    The string representation of the current Byte object, formatted as specified by the format parameter.

    FormatBytes(UInt64)

    Formats a long into the closest bytes string.

    Declaration
    public static string FormatBytes(this ulong bytes)
    Parameters
    Type Name Description
    UInt64 bytes

    The bytes length.

    Returns
    Type Description
    String

    A copy of format in which the format items have been replaced by the string representations of the corresponding arguments.

    Hex2Int(Char)

    Convert hex character to an integer. Return -1 if char is something other than a hex char.

    Declaration
    public static int Hex2Int(this char value)
    Parameters
    Type Name Description
    Char value

    The c.

    Returns
    Type Description
    Int32

    Converted integer.

    Humanize(Boolean)

    Humanizes (make more human-readable) an boolean.

    Declaration
    public static string Humanize(this bool value)
    Parameters
    Type Name Description
    Boolean value

    if set to true [value].

    Returns
    Type Description
    String

    A String that represents the current boolean.

    Humanize(Object)

    Humanizes (make more human-readable) the specified value.

    Declaration
    public static string Humanize(this object value)
    Parameters
    Type Name Description
    Object value

    The value.

    Returns
    Type Description
    String

    A String that represents the current object.

    Humanize(String)

    Humanizes (make more human-readable) an identifier-style string in either camel case or snake case. For example, CamelCase will be converted to Camel Case and Snake_Case will be converted to Snake Case.

    Declaration
    public static string Humanize(this string value)
    Parameters
    Type Name Description
    String value

    The identifier-style string.

    Returns
    Type Description
    String

    A String humanized.

    Indent(String, Int32)

    Indents the specified multi-line text with the given amount of leading spaces per line.

    Declaration
    public static string Indent(this string value, int spaces = 4)
    Parameters
    Type Name Description
    String value

    The text.

    Int32 spaces

    The spaces.

    Returns
    Type Description
    String

    A String that represents the current object.

    RemoveControlChars(String, Char[])

    Removes the control characters from a string except for those specified.

    Declaration
    public static string RemoveControlChars(this string value, params char[] excludeChars)
    Parameters
    Type Name Description
    String value

    The input.

    Char[] excludeChars

    When specified, these characters will not be removed.

    Returns
    Type Description
    String

    A string that represents the current object.

    ReplaceAll(String, String, Char[])

    Replaces all chars in a string.

    Declaration
    public static string ReplaceAll(this string value, string replaceValue, params char[] chars)
    Parameters
    Type Name Description
    String value

    The value.

    String replaceValue

    The replace value.

    Char[] chars

    The chars.

    Returns
    Type Description
    String

    The string with the characters replaced.

    Slice(String, Int32, Int32)

    Retrieves a section of the string, inclusive of both, the start and end indexes. This behavior is unlike JavaScript's Slice behavior where the end index is non-inclusive If the string is null it returns an empty string.

    Declaration
    public static string Slice(this string this, int startIndex, int endIndex)
    Parameters
    Type Name Description
    String this

    The string.

    Int32 startIndex

    The start index.

    Int32 endIndex

    The end index.

    Returns
    Type Description
    String

    Retrieves a substring from this instance.

    SliceLength(String, Int32, Int32)

    Gets a part of the string clamping the length and startIndex parameters to safe values. If the string is null it returns an empty string. This is basically just a safe version of string.Substring.

    Declaration
    public static string SliceLength(this string this, int startIndex, int length)
    Parameters
    Type Name Description
    String this

    The string.

    Int32 startIndex

    The start index.

    Int32 length

    The length.

    Returns
    Type Description
    String

    Retrieves a substring from this instance.

    Stringify(Object)

    Returns text representing the properties of the specified object in a human-readable format. While this method is fairly expensive computationally speaking, it provides an easy way to examine objects.

    Declaration
    public static string Stringify(this object this)
    Parameters
    Type Name Description
    Object this

    The object.

    Returns
    Type Description
    String

    A String that represents the current object.

    TextPositionAt(String, Int32)

    Gets the line and column number (i.e. not index) of the specified character index. Useful to locate text in a multi-line string the same way a text editor does. Please not that the tuple contains first the line number and then the column number.

    Declaration
    public static Tuple<int, int> TextPositionAt(this string value, int charIndex)
    Parameters
    Type Name Description
    String value

    The string.

    Int32 charIndex

    Index of the character.

    Returns
    Type Description
    Tuple<Int32, Int32>

    A 2-tuple whose value is (item1, item2).

    ToJson(Object, Boolean)

    Outputs JSON string representing this object.

    Declaration
    public static string ToJson(this object this, bool format = true)
    Parameters
    Type Name Description
    Object this

    The object.

    Boolean format

    if set to true format the output.

    Returns
    Type Description
    String

    A String that represents the current object.

    ToLines(String)

    Splits the specified text into r, n or rn separated lines.

    Declaration
    public static string[] ToLines(this string this)
    Parameters
    Type Name Description
    String this

    The text.

    Returns
    Type Description
    String[]

    An array whose elements contain the substrings from this instance that are delimited by one or more characters in separator.

    ToSafeFilename(String)

    Makes the file name system safe.

    Declaration
    public static string ToSafeFilename(this string value)
    Parameters
    Type Name Description
    String value

    The s.

    Returns
    Type Description
    String

    A string with a safe file name.

    ToStringInvariant(Object)

    Returns a string that represents the given item It tries to use InvariantCulture if the ToString(IFormatProvider) overload exists.

    Declaration
    public static string ToStringInvariant(this object this)
    Parameters
    Type Name Description
    Object this

    The item.

    Returns
    Type Description
    String

    A String that represents the current object.

    ToStringInvariant<T>(T)

    Returns a string that represents the given item It tries to use InvariantCulture if the ToString(IFormatProvider) overload exists.

    Declaration
    public static string ToStringInvariant<T>(this T item)
    Parameters
    Type Name Description
    T item

    The item.

    Returns
    Type Description
    String

    A String that represents the current object.

    Type Parameters
    Name Description
    T

    The type to get the string.

    Truncate(String, Int32)

    Truncates the specified value.

    Declaration
    public static string Truncate(this string value, int maximumLength)
    Parameters
    Type Name Description
    String value

    The value.

    Int32 maximumLength

    The maximum length.

    Returns
    Type Description
    String

    Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.

    Truncate(String, Int32, String)

    Truncates the specified value and append the omission last.

    Declaration
    public static string Truncate(this string value, int maximumLength, string omission)
    Parameters
    Type Name Description
    String value

    The value.

    Int32 maximumLength

    The maximum length.

    String omission

    The omission.

    Returns
    Type Description
    String

    Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.

    Comments

    Back to top Copyright © 2017-2019 Unosquare