# NativeText

> An unmanaged, mutable, resizable UTF-8 string.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Collections](/engine/6000.7/script-reference/unity/collections.md)
* **Assembly:** UnityEngine.ManagedKernelModule
* **Implements:** [INativeList\<byte>](/engine/6000.7/script-reference/unity/collections/inativelist1.md), [IIndexable\<byte>](/engine/6000.7/script-reference/unity/collections/iindexable1.md), [INativeDisposable](/engine/6000.7/script-reference/unity/collections/inativedisposable.md), [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable), [IUTF8Bytes](/engine/6000.7/script-reference/unity/collections/iutf8bytes.md), [IComparable\<string>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<string>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<NativeText>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<NativeText>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<FixedString32Bytes>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<FixedString32Bytes>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<FixedString64Bytes>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<FixedString64Bytes>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<FixedString128Bytes>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<FixedString128Bytes>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<FixedString512Bytes>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<FixedString512Bytes>](https://learn.microsoft.com/dotnet/api/system.iequatable-1), [IComparable\<FixedString4096Bytes>](https://learn.microsoft.com/dotnet/api/system.icomparable-1), [IEquatable\<FixedString4096Bytes>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct NativeText : INativeList<byte>, IIndexable<byte>, INativeDisposable, IDisposable, IUTF8Bytes, IComparable<string>, IEquatable<string>, IComparable<NativeText>, IEquatable<NativeText>, IComparable<FixedString32Bytes>, IEquatable<FixedString32Bytes>, IComparable<FixedString64Bytes>, IEquatable<FixedString64Bytes>, IComparable<FixedString128Bytes>, IEquatable<FixedString128Bytes>, IComparable<FixedString512Bytes>, IEquatable<FixedString512Bytes>, IComparable<FixedString4096Bytes>, IEquatable<FixedString4096Bytes>
```

## Remarks

The string is always null-terminated, meaning a zero byte always immediately follows the last character.

## Static Fields

| Value                                                                                      | Description                                                     |
| ------------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
| [MaxCapacity](/engine/6000.7/script-reference/unity/collections/nativetext/maxcapacity.md) | The maximum number of elements this type of container can hold. |

## Constructors

| Constructor                                                                                                                                                                                                                       | Description                                                                                       |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [NativeText(System.Int32,Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(int-allocator\))                                                                          | Initializes and returns an instance of NativeText.                                                |
| [NativeText(System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(int-allocatorhandle\))                                             | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(System.String,Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(string-allocator\))                                                                      | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(System.String,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(string-allocatorhandle\))                                         | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(allocator\))                                                                                           | Initializes and returns an instance of NativeText with an initial capacity of 512 bytes.          |
| [NativeText(Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(allocatorhandle\))                                                              | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString128Bytes@,Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring128bytes-allocator\))                                | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString128Bytes@,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring128bytes-allocatorhandle\))   | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString32Bytes@,Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring32bytes-allocator\))                                  | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString32Bytes@,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring32bytes-allocatorhandle\))     | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString4096Bytes@,Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring4096bytes-allocator\))                              | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString4096Bytes@,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring4096bytes-allocatorhandle\)) | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString512Bytes@,Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring512bytes-allocator\))                                | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString512Bytes@,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring512bytes-allocatorhandle\))   | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString64Bytes@,Unity.Collections.Allocator)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring64bytes-allocator\))                                  | Initializes and returns an instance of NativeText with the characters copied from another string. |
| [NativeText(Unity.Collections.FixedString64Bytes@,Unity.Collections.AllocatorManager.AllocatorHandle)](/engine/6000.7/script-reference/unity/collections/nativetext/ctor.md#nativetext\(fixedstring64bytes-allocatorhandle\))     | Initializes and returns an instance of NativeText with the characters copied from another string. |

## Properties

| Property                                                                               | Description                                                                                                                                           |
| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Capacity](/engine/6000.7/script-reference/unity/collections/nativetext/capacity.md)   | The current capacity in bytes of this string.                                                                                                         |
| [IsCreated](/engine/6000.7/script-reference/unity/collections/nativetext/iscreated.md) | Whether this string's character buffer has been allocated (and not yet deallocated).                                                                  |
| [IsEmpty](/engine/6000.7/script-reference/unity/collections/nativetext/isempty.md)     | Whether this string has no characters.                                                                                                                |
| [this\[\]](/engine/6000.7/script-reference/unity/collections/nativetext/item.md)       | The byte at an index. Note that writing to a NativeText.Readonly is not supported; the setter of this property throws when safety checks are enabled. |
| [Length](/engine/6000.7/script-reference/unity/collections/nativetext/length.md)       | The current length in bytes of this string.                                                                                                           |
| [Value](/engine/6000.7/script-reference/unity/collections/nativetext/value.md)         | A copy of this string as a managed string.                                                                                                            |

## Methods

| Method                                                                                         | Description                                                                |
| ---------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| [Add](/engine/6000.7/script-reference/unity/collections/nativetext/add.md)                     | Appends a byte.                                                            |
| [AsReadOnly](/engine/6000.7/script-reference/unity/collections/nativetext/asreadonly.md)       | Returns a readonly version of this NativeText instance.                    |
| [Clear](/engine/6000.7/script-reference/unity/collections/nativetext/clear.md)                 | Sets the length to 0.                                                      |
| [CompareTo](/engine/6000.7/script-reference/unity/collections/nativetext/compareto.md)         | Returns the lexicographical sort order of this string relative to another. |
| [Dispose](/engine/6000.7/script-reference/unity/collections/nativetext/dispose.md)             | Releases all resources (memory and safety handles).                        |
| [ElementAt](/engine/6000.7/script-reference/unity/collections/nativetext/elementat.md)         | Returns a reference to the byte (not character) at an index.               |
| [Equals](/engine/6000.7/script-reference/unity/collections/nativetext/equals.md)               | Returns true if this string and another object are equal.                  |
| [GetEnumerator](/engine/6000.7/script-reference/unity/collections/nativetext/getenumerator.md) | Returns an enumerator for iterating over the characters of the NativeText. |
| [GetHashCode](/engine/6000.7/script-reference/unity/collections/nativetext/gethashcode.md)     | Returns a hash code of this string.                                        |
| [GetUnsafePtr](/engine/6000.7/script-reference/unity/collections/nativetext/getunsafeptr.md)   | Returns a pointer to this string's character buffer.                       |
| [ToString](/engine/6000.7/script-reference/unity/collections/nativetext/tostring.md)           | Returns a managed string copy of this string.                              |
| [TryResize](/engine/6000.7/script-reference/unity/collections/nativetext/tryresize.md)         | Attempt to set the length in bytes of this string.                         |

## Operators

| Operator                                                                                     | Description                              |
| -------------------------------------------------------------------------------------------- | ---------------------------------------- |
| [operator ==](/engine/6000.7/script-reference/unity/collections/nativetext/op-equality.md)   | Returns true if two strings are equal.   |
| [operator !=](/engine/6000.7/script-reference/unity/collections/nativetext/op-inequality.md) | Returns true if two strings are unequal. |

## Structs

| Struct                                                                                              | Description                                                                               |
| --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| [NativeText.Enumerator](/engine/6000.7/script-reference/unity/collections/nativetext/enumerator.md) | An enumerator over the characters (not bytes) of a NativeText.                            |
| [NativeText.ReadOnly](/engine/6000.7/script-reference/unity/collections/nativetext/readonly.md)     | A read-only alias for the value of a NativeText. Does not have its own allocated storage. |
