StringProtocol

protocol StringProtocol : BidirectionalCollection, Comparable, ExpressibleByStringInterpolation, Hashable, LosslessStringConvertible, TextOutputStream, TextOutputStreamable where Self.Element == Character, Self.Index == String.Index, Self.StringInterpolation == DefaultStringInterpolation, Self.SubSequence : StringProtocol

These are a variety of cool String extensions that add some great extra cheese on the pizza.

  • This allows us to find the first index of a substring.

    Declaration

    Swift

    func index(of inString: Self, options inOptions: String.CompareOptions = []) -> Index?

    Parameters

    of

    The substring we’re looking for.

    options

    The String options for the search.

    Return Value

    The index of the first occurrence. Nil, if does not occur.

  • This allows us to find the last index of a substring.

    Declaration

    Swift

    func endIndex(of inString: Self, options inOptions: String.CompareOptions = []) -> Index?

    Parameters

    of

    The substring we’re looking for.

    options

    The String options for the search.

    Return Value

    The index of the last occurrence. Nil, if does not occur.

  • This returns an Array of indexes that map all the occurrences of a given substring.

    Declaration

    Swift

    func indexes(of inString: Self, options inOptions: String.CompareOptions = []) -> [Index]

    Parameters

    of

    The substring we’re looking for.

    options

    The String options for the search.

    Return Value

    an Array, containing the indexes of each occurrence. Empty Array, if does not occur.

  • This returns an Array of Index Ranges that map all the occurrences of a given substring.

    Declaration

    Swift

    func ranges(of inString: Self, options inOptions: String.CompareOptions = []) -> [Range<Index>]

    Parameters

    of

    The substring we’re looking for.

    options

    The String options for the search.

    Return Value

    an Array, containing the Ranges that map each occurrence. Empty Array, if does not occur.