How to join a array to string in Python

To join a array to string in Python you can use the following snippet.

Sample Python

def JoinArray(input, delimiter, appendToEnd):
	delimiter = ';'
	joinedString = delimiter.join(input)
	if appendToEnd:
		joinedString = joinedString + delimiter
		return joinedString
	else:
		return joinedString

list = ['This', 'is', 'a', 'Test','!']
print JoinArray(list, ';', False)

Please rate this snippet

How to join a array to string in Java

To join a array to string in Java you can use the following snippet.

Sample Java

public static String JoinArraylist(List<String> input, String delimiter, Boolean appendToEnd){
	Iterator<String> iteratorString = input.iterator();
	StringBuilder stringBuilder = new StringBuilder();
	for (;;) {
		stringBuilder.append(iteratorString.next());
		if (!iteratorString.hasNext()){ 
			break;
		}
		stringBuilder.append(delimiter);
	}
	if(appendToEnd){
		stringBuilder.append(delimiter);
	}
	return stringBuilder.toString();
}

Please rate this snippet

How to split a string into collection in VBA

To split a string into collection in VBA you can use the following snippet.

Sample VBA

Public Function SplitStringToCollection(sInput As String, Optional sSplitter As String = ";") As Collection
Dim lCounter As Long
Dim sTemp() As String

On Error GoTo errHandler
Set SplitStringToCollection = New Collection
sTemp = Split(sInput, sSplitter)
For lCounter = 0 To UBound(sTemp)
    If (CStr(Replace(sTemp(lCounter), sSplitter, vbNullString)) <> vbNullString) Then
        SplitStringToCollection.Add CStr(Replace(sTemp(lCounter), sSplitter, vbNullString))
    End If
Next lCounter
Exit Function

errHandler:
Set SplitStringToCollection = New Collection
'handle the exception your way
End Function

Please rate this snippet