1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Public Function CouperChaine(ByVal uneChaine As String, ByVal n As Integer)
'cette fonction coupe une chaine tous les n caractères
'et insere un retour a la ligne entre chaque coupure
Dim tmp As String
Dim maChaine As String
Dim retourChariot As String
Dim i As Integer
retourChariot = vbCrLf 'retour a la ligne
maChaine = ""
If InStr(uneChaine, " ") > 0 Then
For i = 1 To Len(uneChaine)
'on parcours la chaine tous les n caractères jusqu'à
'la fin de la chaine
tmp = tmp & Mid(uneChaine, i, 1)
If Len(tmp) > n Or i = Len(uneChaine) Then
If Right(tmp, 1) <> " " And Right(tmp, 1) <> "," And Right(tmp, 1) <> "." And (Len(uneChaine) - i) > 0 Then
tmp = Mid(tmp, 1, InStrRev(tmp, " "))
i = i - (n - InStrRev(tmp, " ") + 1)
End If
maChaine = maChaine & tmp & retourChariot
tmp = ""
If n > 10 Then
n = n - 3
End If
End If
Next
Else
For i = 1 To Len(uneChaine)
'on parcours la chaine tous les n caractères jusqu'à
'la fin de la chaine
tmp = tmp & Mid(uneChaine, i, 1)
If Len(tmp) > n Or i = Len(uneChaine) Then
maChaine = maChaine & tmp & retourChariot
tmp = ""
If n > 10 Then
n = n - 3
End If
End If
Next
End If
Return maChaine
End Function |
Partager