Instance Method

common​Prefix(with:​options:​)

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

Declaration

func commonPrefix(with str: String, options mask: NSString.CompareOptions = []) -> String

Parameters

a​String

The string with which to compare the receiver.

mask

Options for the comparison. The following search options may be specified by combining them with the C bitwise OR operator: NSCase​Insensitive​Search, NSLiteral​Search. See String Programming Guide for details on these options.

Return Value

A string containing characters the receiver and a​String have in common, starting from the beginning of each up to the first characters that aren’t equivalent.

Discussion

The returned string is based on the characters of the receiver. For example, if the receiver is “Ma¨dchen” and a​String is “Mädchenschule”, the string returned is “Ma¨dchen”, not “Mädchen”.

See Also

Related Symbols

func has​Prefix(String)

Returns a Boolean value that indicates whether a given string matches the beginning characters of the receiver.