---
title: "setMarkedText:selectedRange:"
framework: AppKit
role: symbol
role_heading: Instance Method
platforms: [macOS 10.0+]
path: "appkit/nstextinput/setmarkedtext:selectedrange:"
---

# setMarkedText:selectedRange:

Replaces currently marked text in the receiver’s text storage with the given string and sets the selection to the given range, computed from the beginning of the marked text.

## Declaration

```occ
- (void) setMarkedText:(id) string selectedRange:(NSRange) selRange;
```

## Parameters

- `string`: Either an NSString or an NSAttributedString object; must not be nil.
- `selRange`: The range within aString to set as the selection.

## Discussion

Discussion If there is no marked text, the current selection is replaced. If there is no selection, the string is inserted at the insertion point.

## See Also

### Deprecated methods

- [hasMarkedText](appkit/nstextinput/hasmarkedtext.md)
- [markedRange](appkit/nstextinput/markedrange.md)
- [selectedRange](appkit/nstextinput/selectedrange.md)
- [unmarkText](appkit/nstextinput/unmarktext.md)
- [validAttributesForMarkedText](appkit/nstextinput/validattributesformarkedtext.md)
- [attributedSubstringFromRange:](appkit/nstextinput/attributedsubstringfromrange:.md)
- [insertText:](appkit/nstextinput/inserttext:.md)
- [characterIndexForPoint:](appkit/nstextinput/characterindexforpoint:.md)
- [firstRectForCharacterRange:](appkit/nstextinput/firstrectforcharacterrange:.md)
- [doCommandBySelector:](appkit/nstextinput/docommandbyselector:.md)
- [conversationIdentifier](appkit/nstextinput/conversationidentifier.md)
