---
title: "compare(_:options:range:locale:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/stringprotocol/compare(_:options:range:locale:)"
---

# compare(_:options:range:locale:)

Compares the string using the specified options and returns the lexical ordering for the range.

## Declaration

```swift
func compare<T>(_ aString: T, options mask: String.CompareOptions = [], range: Range<Self.Index>? = nil, locale: Locale? = nil) -> ComparisonResult where T : StringProtocol
```
