# Substring

> Retrieves a substring of this string. The substring starts from a specific character index, and has a specified length.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule

## Substring\<T>(T, int, int)

Retrieves a substring of this string. The substring starts from a specific character index, and has a specified length.

```csharp
public static T Substring<T>(this ref T str, int startIndex, int length) where T : unmanaged, INativeList<byte>, IUTF8Bytes
```

### Parameters

**** (T): A string to get the substring from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Start index of substring.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Length of substring.

### Returns

| Type | Description                                                                  |
| ---- | ---------------------------------------------------------------------------- |
| T    | A new string with length equivalent to `length` that begins at `startIndex`. |

## Substring\<T>(T, int)

Retrieves a substring of this string. The substring starts from a specific character index and continues to the end of the string.

```csharp
public static T Substring<T>(this ref T str, int startIndex) where T : unmanaged, INativeList<byte>, IUTF8Bytes
```

### Parameters

**** (T): A string to get the substring from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Start index of substring.

### Returns

| Type | Description                               |
| ---- | ----------------------------------------- |
| T    | A new string that begins at `startIndex`. |

## Substring(NativeText, int, int, AllocatorHandle)

Retrieves a substring from this string. The substring starts from a specific character index, and has a specified length. Allocates memory to the new substring with the allocator specified.

```csharp
public static NativeText Substring(this ref NativeText str, int startIndex, int length, AllocatorManager.AllocatorHandle allocator)
```

### Parameters

**** (\[NativeText]\(/engine/6000.7/script-reference/unity/collections/nativetext)): A [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) string to get the substring from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Start index of substring.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Length of substring.**** (\[AllocatorHandle]\(/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle)): The [AllocatorManager.AllocatorHandle](/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle.md) allocator type to use.

### Returns

| Type                                                                          | Description                                                                                                                  |
| ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) | A `NativeText` string with a length equivalent to `length` that starts at `startIndex` and an allocator type of `allocator`. |

## Substring(NativeText, int, AllocatorHandle)

Retrieves a substring of this string. The substring starts from a specific character index and continues to the end of the string. Allocates memory to the new substring with the allocator specified.

```csharp
public static NativeText Substring(this ref NativeText str, int startIndex, AllocatorManager.AllocatorHandle allocator)
```

### Parameters

**** (\[NativeText]\(/engine/6000.7/script-reference/unity/collections/nativetext)): A [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) string to get the substring from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Start index of substring.**** (\[AllocatorHandle]\(/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle)): The [AllocatorManager.AllocatorHandle](/engine/6000.7/script-reference/unity/collections/allocatormanager/allocatorhandle.md) allocator type to use.

### Returns

| Type                                                                          | Description                                                                               |
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) | A NativeText string that begins at `startIndex` and has an allocator of type `allocator`. |

## Substring(NativeText, int, int)

Retrieves a substring of this string. The substring starts from a specific character index, and has a specified length. The new substring has the same allocator as the string.

```csharp
public static NativeText Substring(this ref NativeText str, int startIndex, int length)
```

### Parameters

**** (\[NativeText]\(/engine/6000.7/script-reference/unity/collections/nativetext)): A [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) string to get the substring from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Start index of substring.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Length of substring.

### Returns

| Type                                                                          | Description                                                                            |
| ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) | A NativeText string that has length equivalent to `length` and begins at `startIndex`. |

## Substring(NativeText, int)

Retrieves a substring of this string. The substring starts from a specific character index and continues to the end of the string. The new substring has the same allocator as the string.

```csharp
public static NativeText Substring(this ref NativeText str, int startIndex)
```

### Parameters

**** (\[NativeText]\(/engine/6000.7/script-reference/unity/collections/nativetext)): A [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) to get the substring from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Start index of substring.

### Returns

| Type                                                                          | Description                                      |
| ----------------------------------------------------------------------------- | ------------------------------------------------ |
| [NativeText](/engine/6000.7/script-reference/unity/collections/nativetext.md) | A NativeText string that begins at `startIndex`. |
