Modifier

Partager via


StringExtensions Class

Definition

Helpers for working with the String type.

public static class StringExtensions
type StringExtensions = class
Public Module StringExtensions
Inheritance
StringExtensions

Methods

Count(String, Char)

Counts the number of occurrences of a given character into a target String instance.

DangerousGetReference(String)

Returns a reference to the first element within a given String, with no bounds checks.

DangerousGetReferenceAt(String, Int32)

Returns a reference to an element at a specified index within a given String, with no bounds checks.

Enumerate(String)

Enumerates the items in the input String instance, as pairs of value/index values. This extension should be used directly within a foreach loop:

string text = "Hello, world!";

foreach (var item in text.Enumerate())
{
    // Access the index and value of each item here...
    int index = item.Index;
    string value = item.Value;
}

The compiler will take care of properly setting up the foreach loop with the type returned from this method.

GetDjb2HashCode(String)

Gets a content hash from the input String instance using the Djb2 algorithm. For more info, see the documentation for GetDjb2HashCode<T>(ReadOnlySpan<T>).

Tokenize(String, Char)

Tokenizes the values in the input String instance using a specified separator. This extension should be used directly within a foreach loop:

string text = "Hello, world!";

foreach (var token in text.Tokenize(','))
{
    // Access the tokens here...
}

The compiler will take care of properly setting up the foreach loop with the type returned from this method.

Applies to