Function [COLOR="DarkRed"]affiche_proprement[/COLOR](s As String) As String [COLOR="SeaGreen"]' 0[/COLOR]
Dim f As Integer, g As Integer, r As String [COLOR="SeaGreen"]' 1[/COLOR]
r = "": g = -1 [COLOR="SeaGreen"]' 2[/COLOR]
Do While Len(s) [COLOR="SeaGreen"] ' 3[/COLOR]
Select Case Asc(s) [COLOR="SeaGreen"]' 4[/COLOR]
Case 45, 160: f = g >= 0 [COLOR="SeaGreen"]'conservation de "-" comme séparateur ' 5*[/COLOR]
Case 46 [COLOR="SeaGreen"]'"."empêche l'insertion d'une espace ' 6°[/COLOR]
Case 95: s = Replace(s, "_", " ", 1, 1): f = g >= 0 [COLOR="SeaGreen"]'remplacement de "_" par une espace ' 7*[/COLOR]
Case 48 To 57: f = 1 [COLOR="SeaGreen"]'chiffre ' 8*[/COLOR]
Case 65 To 90, 97 To 122: f = 2 [COLOR="SeaGreen"]'lettre majuscule ou minuscule, sans accent ' 9*[/COLOR]
Case Else: f = 0 [COLOR="SeaGreen"]'autre caractère '10[/COLOR]
End Select [COLOR="SeaGreen"] '11[/COLOR]
If f Then [COLOR="SeaGreen"]'chiffre ou lettre ou "-" '12[/COLOR]
If f > 0 And f <> g And g > 0 Then r = r & " " [COLOR="SeaGreen"]'espace sauf en début de ligne ou après "-" '13[/COLOR]
r = r & Left$(s, 1): g = f [COLOR="SeaGreen"]'14[/COLOR]
End If [COLOR="SeaGreen"]'15[/COLOR]
s = Right$(s, Len(s) - 1) [COLOR="SeaGreen"]'16[/COLOR]
Loop [COLOR="SeaGreen"]'17[/COLOR]
r = Replace(r, ". ", "", 1, -1) [COLOR="SeaGreen"]'18°[/COLOR]
[COLOR="DarkRed"]affiche_proprement[/COLOR] = UCase(r) [COLOR="SeaGreen"]'toutes les lettres en majuscules '19*[/COLOR]
End Function [COLOR="SeaGreen"]'20[/COLOR]