<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedStringFormattingOptions/NSAttributedStringFormattingApplyReplacementIndexAttribute",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration Case",
  "symbol" : {
    "kind" : "Enumeration Case",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@E@NSAttributedStringFormattingOptions@NSAttributedStringFormattingApplyReplacementIndexAttribute"
  },
  "title" : "NSAttributedStringFormattingApplyReplacementIndexAttribute"
}
-->

# NSAttributedStringFormattingApplyReplacementIndexAttribute

An option to apply to the replaced portions of text in a format string.

```
NSAttributedStringFormattingApplyReplacementIndexAttribute
```

## Discussion

When creating an attributed string from a format string, specify this option to apply an attribute to all substituted text. Consider the creation of an attributed string using the format string `“Count: %d; Total: %d”`. After generating the attributed string, the creation method applies the [`replacementIndex`](/documentation/Foundation/NSAttributedString/Key/replacementIndex) attribute to the both integer values in the resulting string.

The value of the [`replacementIndex`](/documentation/Foundation/NSAttributedString/Key/replacementIndex) attribute is an `NSNumber` with the replacement’s position in the format string. The value for the first replacement is 1, for the second replacement is 2, and so on. If you include a positional marker in the format string specifier, the value of the attribute reflects that position, regardless of its actual position in the string. For example, the string `“%2@ -- %1@”` causes the first argument to have an index value of `2` and the second argument to have an index value of `1`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)