FutureBasic Logo

<<    Index    >> FutureBasic

concat   function



Syntax 1
newObj = concat( obj1, obj2 [ , obj3 [ ... ] ] )

Syntax 2
newString = concat joinStr,( obj1, obj2 [ , obj3 [ ... ] ] )

Description
The concat function is used to concatenate various Core Foundation (CF) and Foundation framework types. Initially designed for CFStrings, it supports a variety of types, including CFAttributedString, CFArray, CFDictionary, CFSet, NSOrderedSet, NSIndexSet, and NSCountedSet. Additionally, the function supports concatenation of mixed types in specific combinations.

Use the concat keyword followed by the objects to be concatenated, separated by comma ','.

Syntax 2 returns a string with the objects joined by joinStr. This is similar to the function, ArrayComponentsJoinedByString.

Example 1

CFStringRef s = concat( @"Hello, ", @"World!" )

print s // Hello, World!

Example 2

CFStringRef s1 = @"One, ", s2 = @"Two, ", s3 = @"Three, "

CFStringRef string = concat( s1, s2, s3, @"O'Leary" )

print string // One, Two, Three, O'Leary

Example 3

CFArrayRef a1 = @[@"Alpha",@"Bravo"]
CFArrayRef a2 = @[@"Charlie",@"Delta"]
CFArrayRef array = concat( a1, a2 )

print array

// prints
(
  Alpha,
  Bravo,
  Charlie,
  Delta
)

Example 4

Syntax 2 example

CFStringRef string = concat @", ",( @[@"apples",@"pears", @"strawberries", @"melons", @"lemons", @"blueberries"] )
print string

// prints
apples, pears, strawberries, melons, lemons, blueberries

Mixed Type Concatenation
The concat function also supports concatenation of the following mixed type combinations:
CFArray + CFStringAdds a CFString, as an element, to a CFArray.
CFString + CFArrayAppends the elements of a CFArray to a CFString.
CFArray + CFSetConcatenates the contents of a CFSet to a CFArray.
CFSet + CFArrayConcatenates the contents of a CFArray to a CFSet.
CFArray + IndexSetAdds the contents of an IndexSet (as CFNumbers) to a CFArray.

Note: When mixing types, the first object in the list determines the returned object type. For example, if obj1 is a CFString, newObj will also be a CFString.

Example 5

CFArrayRef a1 = @[@"Mike",@"November"]
CFArrayRef a2 = @[@"Oscar",@"Papa"]
CFStringRef s = @"Quebec"
CFArrayRef array = concat( a1, a2, s, @"Romeo" )

print array

// prints
(
  Mike,
  November,
  Oscar,
  Papa,
  Quebec,
  Romeo
)