Contents

CFStringCreateArrayBySeparatingStrings(_:_:_:)

Creates an array of CFString objects from a single CFString object.

Declaration

func CFStringCreateArrayBySeparatingStrings(_ alloc: CFAllocator!, _ theString: CFString!, _ separatorString: CFString!) -> CFArray!

Parameters

  • alloc:

    The allocator to use to allocate memory for the new CFArray object. Pass NULL or Kcfallocatordefault to use the current default allocator.

  • theString:

    The string to be divided into substrings. The substrings should be separated by separatorString.

  • separatorString:

    The string used to separate the substrings in theString.

Return Value

A new array that contains CFString objects that represent substrings of theString, or NULL if there was a problem creating the object. The order of elements in the array is identical to the order of the substrings in theString. If separatorString does not occur in theString, the result is an array containing theString. If separatorString is equal to theString, then the result is an array containing two empty strings. Ownership follows the The Create Rule.

Discussion

This function provides a convenient way to convert units of data captured in a single string to a form (an array) suitable for iterative processing. One or more delimiter characters (or “separator string”) separates the substrings in the source string—these characters are frequently whitespace characters such as tabs and newlines (carriage returns). For example, you might have a file containing a localized list of place names with each name separated by a tab character. You could create a CFString object from this file and call this function on the string to obtain a CFArray object whose elements are these place names.

separatorString is treated as a complete unit. If you specify XYZ as the separator string, then if theString is aXbYZcXYZe, then the returned array contains aXbYZc and e.

See also CFStringCreateByCombiningStrings(_:_:_:).

See Also

Creating a CFString