Function ExplodeChars(ByVal Expression As String, Optional sChar As String = " ", Optional bIncludeLast As Boolean = True) As String
'ExplodeChars => retourne la chaine EXPRESSION entrecoupée d'un caractère SCHAR
'sChar => caractère (taille 1) désiré
'bIncludeLast => se termine par SCHAR ou par le dernier caractère de EXPRESSION
ExplodeChars = vbNullString
' oblige taille EXPRESSION au moins de 1 carac, et taille SCHAR seulement de 1 carac
If Len(Expression) Then
If LenB(sChar) = 2 Then
Dim i As Integer, j As Integer
' formate le retour avec le caractère désiré sur la taille finale
If bIncludeLast Then j = LenB(Expression) Else j = LenB(Expression) - 1
ExplodeChars = String(j, sChar)
' attribue la chaine EXPRESSION 1 carac sur 2
j = 1
For i = 1 To Len(Expression)
Mid$(ExplodeChars, j, 1) = Mid$(Expression, i, 1)
j = j + 2
Next i
End If
End If
End Function
'chaine s = "abcde"
'ExplodeChars(s) renvoie "a b c d e "
'ExplodeChars(s, "@", False) renvoie "a@b@c@d@e"