<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/range(of:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(im)rangeOfString:"
  },
  "title" : "range(of:)"
}
-->

# range(of:)

Finds and returns the range of the first occurrence of a given string within the string.

```
func range(of searchString: String) -> NSRange
```

## Parameters

`searchString`

The string to search for.

## Return Value

An `NSRange` structure giving the location and length in the receiver of the first occurrence of `searchString`. Returns `{``NSNotFound``, 0}` if `searchString` is not found or is empty (`""`).

## Discussion

Invokes [`range(of:options:)`](/documentation/Foundation/NSString/range(of:options:)) with no options.

`NSString` objects are compared by checking the Unicode canonical equivalence of their code point sequences.  The length of the returned range and that of `searchString` may differ if equivalent composed character sequences are matched.

> Important:
> When working with text that’s presented to the user, use the ``doc://com.apple.foundation/documentation/Foundation/NSString/localizedStandardRange(of:)`` method instead.

---

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)