CorString: Join |
Concatenates the specified elements of an array or collection, using the specified separator between each element.
Public Function Join( ByRef Separator As String, ByRef Value As Variant, Optional ByRef StartIndex As Variant, Optional ByRef Count As Variant ) As String
For example, if Separator is ", " and the elements of Value are "apple", "orange", "grape", and "pear", Join(separator, value, 1, 2) returns "orange, grape".
Exception | Condition |
---|---|
ArgumentOutOfRangeException |
StartIndex is less than the lower-bound of Value. -or- Count is less than zero. -or- StartIndex plus Count is greater than the upper-bound of Value. |
The following example concatenates two elements from an array of names of fruit.
Public Sub Main() Dim Value() As String Dim List As Collection Dim Sep As String Dim Result As String Sep = ", " Value = NewStrings("apple", "orange", "grape", "pear") Set List = NewCollection("apple", "orange", "grape", "pear") Debug.Print CorString.Format("Sep = '{0}'", Sep) Debug.Print Debug.Print CorString.Format("Value() = {{'{0}' '{1}' '{2}' '{3}'}}", Value(0), Value(1), Value(2), Value(3)) Result = CorString.Join(Sep, Value, 1, 2) Debug.Print CorString.Format("CorString.Join(Sep, Value, 1, 2) = '{0}'", Result) Debug.Print Debug.Print CorString.Format("List = {{'{0}' '{1}' '{2}' '{3}'}}", List(1), List(2), List(3), List(4)) Result = CorString.Join(Sep, List) Debug.Print CorString.Format("CorString.Join(Sep, List) = '{0}'", Result) End Sub ' This example produces the following output. ' ' Sep = ', ' ' ' Value() = {'apple' 'orange' 'grape' 'pear'} ' CorString.Join(Sep, Value, 1, 2) = 'orange, grape' ' ' List = {'apple' 'orange' 'grape' 'pear'} ' CorString.Join(Sep, List) = 'apple, orange, grape, pear'