---
title: "commonPrefix(with:options:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/stringprotocol/commonprefix(with:options:)"
---

# commonPrefix(with:options:)

Returns a string containing characters this string and the given string have in common, starting from the beginning of each up to the first characters that aren’t equivalent.

## Declaration

```swift
func commonPrefix<T>(with aString: T, options: String.CompareOptions = []) -> String where T : StringProtocol
```
