# SetSearchText

> Sets the search query text.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.Search](/engine/6000.7/script-reference/unityeditor/search.md)
* **Assembly:** UnityEditor

## SetSearchText(string, TextCursorPlacement)

Sets the search query text.

```csharp
void SetSearchText(string searchText, TextCursorPlacement moveCursor = TextCursorPlacement.Default)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text displayed in the search view.**** (\[TextCursorPlacement]\(/engine/6000.7/script-reference/unityeditor/search/textcursorplacement)): Position of the cursor after setting the search text.

### Remarks

![Example ISearchView SetSearchText (SetSearchText)](/api/media?file=/engine/6000.7/media/images/Example_ISearchView_SetSearchText.png)

![Example ISearchView SetSearchText SetCursorPosition (SetSearchText)](/api/media?file=/engine/6000.7/media/images/Example_ISearchView_SetSearchText_SetCursorPosition.png)

.

### Examples

```csharp
using UnityEngine;
using UnityEditor;
using UnityEditor.Search;

static class Example_ISearchView_SetSearchText
{
    [MenuItem("Examples/ISearchView/SetSearchText")]
    public static void SetInitialText()
    {
        var view = SearchService.ShowContextual("asset");

        // Set the initial text of Search view. By default the whole text of the search query will be selected.
        view.SetSearchText("t:prefab");
        Debug.Assert(view.context.searchText == "t:prefab");
    }

    #region SetSearchText_WithCursorPosition
    [MenuItem("Examples/ISearchView/SetSearchText_WithCursorPosition")]
    public static void SetSearchText_WithCursorPosition()
    {
        var view = SearchService.ShowContextual("asset");
        view.SetSearchText("t:material", TextCursorPlacement.MoveLineStart);
    }

    #endregion
}
```

## SetSearchText(string, TextCursorPlacement, int)

Sets the search query text.

```csharp
void SetSearchText(string searchText, TextCursorPlacement moveCursor, int cursorInsertPosition)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Text displayed in the search view.**** (\[TextCursorPlacement]\(/engine/6000.7/script-reference/unityeditor/search/textcursorplacement)): Position of the cursor after setting the search text.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)):&#x20;

### Remarks

![Example ISearchView SetSearchText (SetSearchText)](/api/media?file=/engine/6000.7/media/images/Example_ISearchView_SetSearchText.png)

![Example ISearchView SetSearchText SetCursorPosition (SetSearchText)](/api/media?file=/engine/6000.7/media/images/Example_ISearchView_SetSearchText_SetCursorPosition.png)

.

### Examples

```csharp
using UnityEngine;
using UnityEditor;
using UnityEditor.Search;

static class Example_ISearchView_SetSearchText
{
    [MenuItem("Examples/ISearchView/SetSearchText")]
    public static void SetInitialText()
    {
        var view = SearchService.ShowContextual("asset");

        // Set the initial text of Search view. By default the whole text of the search query will be selected.
        view.SetSearchText("t:prefab");
        Debug.Assert(view.context.searchText == "t:prefab");
    }

    #region SetSearchText_WithCursorPosition
    [MenuItem("Examples/ISearchView/SetSearchText_WithCursorPosition")]
    public static void SetSearchText_WithCursorPosition()
    {
        var view = SearchService.ShowContextual("asset");
        view.SetSearchText("t:material", TextCursorPlacement.MoveLineStart);
    }

    #endregion
}
```
