Table of Contents

Class StringExtensions

Namespace
Stride.Core
Assembly
Stride.Core.dll

Extensions for string class.

public static class StringExtensions
Inheritance
StringExtensions

Methods

Contains(string, char)

Indicate if the string contains a character.

public static bool Contains(this string text, char value)

Parameters

text string

The text

value char

The character to look for.

Returns

bool

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

stringToTest string

The string automatic test.

endChar char

The end character.

Returns

bool

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

EndsWith(string, params char[])

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

public static bool EndsWith(this string stringToTest, params char[] endChars)

Parameters

stringToTest string

The string automatic test.

endChars char[]

The end characters.

Returns

bool

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 StringBuilder, equivalent of IndexOf(char) for a StringBuilder.

public static int IndexOf(this StringBuilder builder, char testChar)

Parameters

builder StringBuilder

The builder.

testChar char

The test character.

Returns

int

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

Exceptions

ArgumentNullException

builder

IndexOfReverse(string, char, int)

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

text string

The text.

charToFind char

The character automatic find.

matchCount int

The number of match before stopping. Default is 1

Returns

int

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

Exceptions

ArgumentNullException

text

ArgumentOutOfRangeException

matchCount;matchCount must be >= 1

IndexOfReverse(string, char, int, int, int)

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

text string

The text.

charToFind char

The character automatic find.

startIndexFromEnd int

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

count int

The number of character positions to be examined.

matchCount int

The number of match before stopping. Default is 1

Returns

int

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

Exceptions

ArgumentNullException

text

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, int)

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

public static int LastIndexOf(this StringBuilder builder, char testChar, int startIndex = 0)

Parameters

builder StringBuilder

The builder.

testChar char

The test character.

startIndex int

The start index.

Returns

int

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

Exceptions

ArgumentNullException

builder

SafeTrim(string)

Safely trim a string.

public static string SafeTrim(this string value)

Parameters

value string

The string value. can be null

Returns

string

The string trimmed.May be null if string was null

Substring(StringBuilder, int)

public static string Substring(this StringBuilder builder, int startIndex)

Parameters

builder StringBuilder
startIndex int

Returns

string

Substring(StringBuilder, int, int)

public static string Substring(this StringBuilder builder, int startIndex, int length)

Parameters

builder StringBuilder
startIndex int
length int

Returns

string

ToFormat(string, params object[])

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

public static string ToFormat(this string stringToFormat, params object[] argumentsToFormat)

Parameters

stringToFormat string

The string automatic format.

argumentsToFormat object[]

The arguments automatic format.

Returns

string

A formatted string. See Format(string, object)