# SetText

> Sets the text content without allocating a managed string.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.UIElements](/engine/6000.7/script-reference/unityengine/uielements.md)
* **Assembly:** UnityEngine.UIElementsModule

## SetText(ReadOnlySpan\<char>)

Sets the text content without allocating a managed string.

```csharp
public void SetText(ReadOnlySpan<char> text)
```

### Parameters

**** (\[ReadOnlySpan\<char>]\(https\://learn.microsoft.com/dotnet/api/system.readonlyspan-1)): The character span to set as the element's text content.

### Remarks

Unlike assigning to [\_text](/engine/6000.7/script-reference/unityengine/uielements/textelement/text.md), this method writes directly into an internal native buffer and defers string materialization until [\_text](/engine/6000.7/script-reference/unityengine/uielements/textelement/text.md) is read. A [ChangeEvent\<T>](/engine/6000.7/script-reference/unityengine/uielements/changeevent1.md) of type `string` is raised only when listeners for value-change events exist in the element's hierarchy; when no such listeners are present, the method is fully allocation-free.

## SetText(char\[], int, int)

Sets the text content from a character array slice without allocating a managed string.

```csharp
public void SetText(char[] sourceText, int start, int length)
```

### Parameters

**** (\[char\[]]\(https\://learn.microsoft.com/dotnet/api/system.char)): The source character array.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The starting index in the array.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of characters to copy.

## SetText(StringBuilder)

Sets the text content from a StringBuilder without allocating a managed string.

```csharp
public void SetText(StringBuilder sb)
```

### Parameters

**** (\[StringBuilder]\(https\://learn.microsoft.com/dotnet/api/system.text.stringbuilder)): The StringBuilder whose contents to copy.

## SetText(float, string)

Formats a float value directly into the text buffer without allocating a managed string.

```csharp
public void SetText(float value, string format = null)
```

### Parameters

**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The float value to display.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): An optional standard or custom numeric format string.

## SetText(int)

Formats an integer value directly into the text buffer without allocating a managed string.

```csharp
public void SetText(int value)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The integer value to display.
