Instance Method

range(of:)

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

Declaration

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:) 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.

See Also

Related Symbols

func range(of: String, options: NSString.CompareOptions = [])

Finds and returns the range of the first occurrence of a given string within the receiver, subject to given options.

func localizedStandardRange(of: String)

Finds and returns the range of the first occurrence of a given string within the receiver by performing a case and diacritic insensitive, locale-aware search.