# Find and Replace

The RadSyntax editor provides an easy and intuitive way to search for a given text in the document as well as replace occurrences of this text.

## Find and Replace Dialog

By pressing the **Ctrl + F** key combination you can open the find dialog which consist of UI to find a particular string and replace it with another. By using the arrow buttons, you can navigate to the previous or next occurrence of the search text. You can also highlight all occurrences of the text by clicking the `Find All` button. You can also replace the next occurrence of the string or all occurrences via the `Replace` and `Replace All` buttons respectively. To further customize the find and replace logic, you can use the buttons to apply case sensitivity, enable or disable matching of whole words, and use regex expressions.

> caption The find dialog

![The Find Dialog](https://www.telerik.com/products/wpf/documentation/assets/0208693ee7f93ca03e06a8315e9105a6/syntaxeditor-find-dialog.png)

## Programmatic Search

You can also search in the document programmatically by using the following methods exposed by the RadSyntaxEditor control.

### Find

The `Find` method takes as arguments the search string and the index from which to start the search. Optionally, you can also pass a parameter to control whether the casing of the letters should be matched and to specify whether the search string is a regular expression. The different overloads of the method are listed below.

* **Span? Find(string searchText, int startIndex)**
* **Span? Find(string searchText, int startIndex, bool useRegularExpression)**
* **Span? Find(string searchText, int startIndex, bool matchCase, bool useRegularExpression)**
* **Span? Find(string searchText, int startIndex, bool matchCase, bool useRegularExpression, bool matchWord)**

### FindAll

The `FindAll` method is identical to the Find method, with the difference being that it does not take a starting index as an argument and returns **all occurrences** of the searched string in the document.

* **IEnumerable<Span> FindAll(string searchText)**
* **IEnumerable<Span> FindAll(string searchText, bool useRegularExpression)**
* **IEnumerable<Span> FindAll(string searchText, bool matchCase, bool useRegularExpression)**
* **IEnumerable<Span> FindAll(string searchText, bool matchCase, bool useRegularExpression, bool matchWord)**

### FindPrevious

The `FindPrevious` method works similarly to the Find method, with the difference that the search is performed from the starting index towards the beginning of the document. It has a single overload with the following definition:

* **Span? FindPrevious(string searchText, int startIndex, bool matchCase)**
* **Span? FindPrevious(string searchText, int startIndex, bool matchCase, bool useRegularExpression, bool matchWord)**

### NavigateNextMatch and NavigatePreviousMatch

The `NavigateNextMatch` and `NavigatePreviousMatch` methods can be used to find the next and previous occurrence of the searched text with regards to the current position of the control's **caret**. The search performed by these methods is case-insensitive. All folded regions which contain the matched span are unfolded when this method is invoked.

* **void NavigateNextMatch(string searchText)**
* **void NavigatePreviousMatch(string searchText)**

### HighlightAllMatches

The `HighlightAllMatches` method finds all occurrences of the searched text in the document and, if there is a registered `TextSearchHighlightTagger`, highlights them by using the specified `TextFormatDefinitions`. The performed search is case-insensitive.

* **void HighlightAllMatches(string searchText)**

## ReplaceAllMatches

The `RemplaceAllMatches` method finds all occurrences of the searched text and replaces them with the new input.

* **int ReplaceAllMatches(string searchText, string replaceText, bool matchCase, bool useRegularExpression)**
* **int ReplaceAllMatches(string searchText, string replaceText, bool matchCase, bool useRegularExpression, bool matchWord)**

### OpenFindDialog and CloseFindDialog

Invoking the `OpenFileDialog` method opens the find and replace dialog with the specified search text in the search textbox. The `CloseFindDialog` in turn sets the dialog's `Visibility` to `Collapsed`.

* **void OpenFindDialog(string searchText)**
* **void CloseFindDialog()**

## SearchPanelWidth

The RadSyntaxEditor control exposes a `SearchPanelWidth` property which you can use to control the width of the find and replace dialog.

> Setting this property may be necessary if you've localized the control in a language other than English or have defined custom strings for the buttons of the dialog, which, in turn, clips their content.

**Setting SearchPanelWidth**

```XAML

<telerik:RadSyntaxEditor x:Name="SyntaxEditor" SearchPanelWidth="600" />
```

**Setting SearchPanelWidth**

```C#

this.SyntaxEditor.SearchPanelWidth = 600;
```

```VB.NET

Me.SyntaxEditor.SearchPanelWidth = 600
```

## See Also

* [Selection](https://www.telerik.com/products/wpf/documentation/controls/radsyntaxeditor/features/selection)
* [IntelliPrompts](https://www.telerik.com/products/wpf/documentation/controls/radsyntaxeditor/features/intelliprompts)
