Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    StringExtensions Class

    Namespace: Stride.Core
    Assembly: Stride.Core.dll

    Extensions for System.String class.

    System.Object → StringExtensions
    Derived from StringExtensions:

    public static class StringExtensions
    Name Description
    Methods
    Contains(String, Char)

    Indicate if the string contains a character.

    EndsWith(String, Char)

    Determines whether the end of this string ends by the specified character.

    EndsWith(String, Char[])

    Determines whether the end of this string ends by the specified characters.

    IndexOf(StringBuilder, Char)

    Calculates the index of a char inside the following System.Text.StringBuilder, equivalent of System.String.IndexOf(System.Char) for a StringBuilder.

    IndexOfReverse(String, Char, Int32)

    Reports the index number, or character position, of the first occurrence of the specified Unicode character in the current String object. The search starts at a specified character position starting from the end and examines a specified number of character positions.

    IndexOfReverse(String, Char, Int32, Int32, Int32)

    Reports the index number, or character position, of the first occurrence of the specified Unicode character in the current String object. The search starts at a specified character position starting from the end and examines a specified number of character positions.

    LastIndexOf(StringBuilder, Char, Int32)

    Calculates the last index of a char inside the following System.Text.StringBuilder, equivalent of System.String.LastIndexOf(System.Char) for a StringBuilder.

    SafeTrim(String)

    Safely trim a string.

    Substring(StringBuilder, Int32)
    Substring(StringBuilder, Int32, Int32)
    ToFormat(String, Object[])

    Extension to format a string using System.String.Format(System.String,System.Object) method by allowing to use it directly on a string.

    | Improve this Doc View Source

    Methods


    Contains(String, Char)

    Indicate if the string contains a character.

    public static bool Contains(this string text, char value)
    Parameters
    Type Name Description
    System.String text

    The text

    System.Char value

    The character to look for.

    Returns
    Type Description
    System.Boolean

    A boolean indicating if at least one instance of value is present in text


    EndsWith(String, Char)

    Determines whether the end of this string ends by the specified character.

    public static bool EndsWith(this string stringToTest, char endChar)
    Parameters
    Type Name Description
    System.String stringToTest

    The string automatic test.

    System.Char endChar

    The end character.

    Returns
    Type Description
    System.Boolean

    true if the end of this string ends by the specified character, false otherwise.


    EndsWith(String, Char[])

    Determines whether the end of this string ends by the specified characters.

    public static bool EndsWith(this string stringToTest, params char[] endChars)
    Parameters
    Type Name Description
    System.String stringToTest

    The string automatic test.

    System.Char[] endChars

    The end characters.

    Returns
    Type Description
    System.Boolean

    true if the end of this string ends by the specified character, false otherwise.


    IndexOf(StringBuilder, Char)

    Calculates the index of a char inside the following System.Text.StringBuilder, equivalent of System.String.IndexOf(System.Char) for a StringBuilder.

    public static int IndexOf(this StringBuilder builder, char testChar)
    Parameters
    Type Name Description
    System.Text.StringBuilder builder

    The builder.

    System.Char testChar

    The test character.

    Returns
    Type Description
    System.Int32

    A position to the character found, or -1 if not found.

    Exceptions
    Type Condition
    System.ArgumentNullException

    builder


    IndexOfReverse(String, Char, Int32)

    Reports the index number, or character position, of the first occurrence of the specified Unicode character in the current String object. The search starts at a specified character position starting from the end and examines a specified number of character positions.

    public static int IndexOfReverse(this string text, char charToFind, int matchCount = 1)
    Parameters
    Type Name Description
    System.String text

    The text.

    System.Char charToFind

    The character automatic find.

    System.Int32 matchCount

    The number of match before stopping. Default is 1

    Returns
    Type Description
    System.Int32

    The character position of the value parameter for the specified character if it is found, or -1 if it is not found.

    Exceptions
    Type Condition
    System.ArgumentNullException

    text

    System.ArgumentOutOfRangeException

    matchCount;matchCount must be >= 1


    IndexOfReverse(String, Char, Int32, Int32, Int32)

    Reports the index number, or character position, of the first occurrence of the specified Unicode character in the current String object. The search starts at a specified character position starting from the end and examines a specified number of character positions.

    public static int IndexOfReverse(this string text, char charToFind, int startIndexFromEnd, int count, int matchCount = 1)
    Parameters
    Type Name Description
    System.String text

    The text.

    System.Char charToFind

    The character automatic find.

    System.Int32 startIndexFromEnd

    The starting index number for the search relative to the end of the string.

    System.Int32 count

    The number of character positions to be examined.

    System.Int32 matchCount

    The number of match before stopping. Default is 1

    Returns
    Type Description
    System.Int32

    The character position of the value parameter for the specified character if it is found, or -1 if it is not found.

    Exceptions
    Type Condition
    System.ArgumentNullException

    text

    System.ArgumentOutOfRangeException

    count;Count must be a positive value or startIndexFromEnd;StartIndexFromEnd must be a positive value or startIndexFromEnd;StartIndexFromEnd must be within the range of the string length or count;Count must be in the range of the string length minus the startIndexFromEnd


    LastIndexOf(StringBuilder, Char, Int32)

    Calculates the last index of a char inside the following System.Text.StringBuilder, equivalent of System.String.LastIndexOf(System.Char) for a StringBuilder.

    public static int LastIndexOf(this StringBuilder builder, char testChar, int startIndex = 0)
    Parameters
    Type Name Description
    System.Text.StringBuilder builder

    The builder.

    System.Char testChar

    The test character.

    System.Int32 startIndex

    The start index.

    Returns
    Type Description
    System.Int32

    A position to the character found, or -1 if not found.

    Exceptions
    Type Condition
    System.ArgumentNullException

    builder


    SafeTrim(String)

    Safely trim a string.

    public static string SafeTrim(this string value)
    Parameters
    Type Name Description
    System.String value

    The string value. can be null

    Returns
    Type Description
    System.String

    The string trimmed.May be null if string was null


    Substring(StringBuilder, Int32)

    public static string Substring(this StringBuilder builder, int startIndex)
    Parameters
    Type Name Description
    System.Text.StringBuilder builder
    System.Int32 startIndex
    Returns
    Type Description
    System.String

    Substring(StringBuilder, Int32, Int32)

    public static string Substring(this StringBuilder builder, int startIndex, int length)
    Parameters
    Type Name Description
    System.Text.StringBuilder builder
    System.Int32 startIndex
    System.Int32 length
    Returns
    Type Description
    System.String

    ToFormat(String, Object[])

    Extension to format a string using System.String.Format(System.String,System.Object) method by allowing to use it directly on a string.

    public static string ToFormat(this string stringToFormat, params object[] argumentsToFormat)
    Parameters
    Type Name Description
    System.String stringToFormat

    The string automatic format.

    System.Object[] argumentsToFormat

    The arguments automatic format.

    Returns
    Type Description
    System.String

    A formatted string. See System.String.Format(System.String,System.Object)


    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation