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

# contains(_:)

Returns a Boolean value indicating whether the string contains a given string by performing a case-sensitive, locale-unaware search.

```
func contains(_ str: String) -> Bool
```

## Parameters

`str`

The string to search for. This value must not be `nil`.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the receiver contains `str`, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Calling this method is equivalent to calling [`range(of:options:)`](/documentation/Foundation/NSString/range(of:options:)) with no options.

> Important:
> When working with text that’s presented to the user, use ``doc://com.apple.foundation/documentation/Foundation/NSString/localizedStandardContains(_:)`` or ``doc://com.apple.foundation/documentation/Foundation/NSString/localizedCaseInsensitiveContains(_:)`` 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)