Contents

replaceSelectedText(_:withText:)

Replaces text with new text, either within the current selection or near the cursor.

Declaration

func replaceSelectedText(_ text: String, withText replacementText: String)

Parameters

  • text:

    The text to find and replace.

  • replacementText:

    The text to insert in place of the found text.

Mentioned in

Discussion

This method’s behavior depends on the current selection state:

  • If text is selected, this method replaces occurrences of text within the selection with replacementText.

  • If the cursor is positioned without a selection, this method searches for text immediately before the cursor and replaces it with replacementText.

  • If the cursor is at the start of an editable element, this method searches for text immediately after the cursor instead.

See Also

Inserting and replacing text