public init(_ inString: String)

This init extracts an IPV6 address, and, if applicable, TCP port, from a given string.

The definition of an IPV6 address is: XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX

Where X is 0…F (hexadecimal). There are shortcuts (discussed below), but we assume leading zeroes, and all zeores are represented.

Each segment is a positive integer, from 0 - 65535 (FFFF in hexadecimal).

If there is an additional TCP port, then the IP address is bracketed, and followed immediately by a colon (:), then immediately by a positive integer, like this: [XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX]:Y

Where Y is a positive integer


You can specify a range of 0-filled elements by using :: as a shortcut. This is only allowed once in the entire address, so:

XXXX:0000:0000:0000:XXXX:0000:0000:XXXX can be written as XXXX::XXXX:0000:0000:XXXX or XXXX:0000:0000:0000:XXXX::XXXX

Usually, the first shortcut will be selected, as it’s the longest range.

You can have a maximum of four (4) hexadecimal characters in an element. Case of the hex digits is usually lowercased, as a convention, but uppercased is allowed. We use lowercase.

You cannot have characters other than 0-9, a-f (or A-F) in an element.

You must separate elements with colons (:). If you are specifying a port, you must wrap the address in brackets ([]). You must have BOTH brackets if you are wrapping the address.

You can wrap an address in brackets, even if you do not specify a port.

If you specify a port, it must appear after a colon (:), after the closing bracket (]), so you would have ]:12345, to specify TCP Port 12345.

You can have a maximum of eight (8) elements.

Illegal formats and syntax errors result in no address being set. This method does not guess.

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



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



    The string to be searched.


    The substring we’re looking for.


    The String options for the search.

    Return Value

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