Instance Method

hasPrefix(_:)

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

Declaration

func hasPrefix(_ str: String) -> Bool

Parameters

aString

A string.

Return Value

true if aString matches the beginning characters of the receiver, otherwise false. Returns false if aString is empty.

Discussion

This method is a convenience for comparing strings using the NSAnchoredSearch option. See String Programming Guide for more information.

See Also

Identifying and Comparing Strings

func caseInsensitiveCompare(String) -> ComparisonResult

Returns the result of invoking compare(_:options:) with NSCaseInsensitiveSearch as the only option.

func localizedCaseInsensitiveCompare(String) -> ComparisonResult

Compares the string with a given string using a case-insensitive, localized, comparison.

func compare(String) -> ComparisonResult

Returns the result of invoking compare(_:options:range:) with no options and the receiver’s full extent as the range.

func localizedCompare(String) -> ComparisonResult

Compares the string and a given string using a localized comparison.

func compare(String, options: NSString.CompareOptions) -> ComparisonResult

Compares the string with the specified string using the given options.

func compare(String, options: NSString.CompareOptions, range: NSRange, locale: Any?) -> ComparisonResult

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

func localizedStandardCompare(String) -> ComparisonResult

Compares strings as sorted by the Finder.

func hasSuffix(String) -> Bool

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

func isEqual(to: String) -> Bool

Returns a Boolean value that indicates whether a given string is equal to the receiver using a literal Unicode-based comparison.

var hash: Int

An unsigned integer that can be used as a hash table address.

struct NSString.CompareOptions

These values represent the options available to many of the string classes’ search and comparison methods.

struct NSString.EncodingConversionOptions

Options for converting string encodings.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software