@Propercase en LS

@Propercase en LS

Messagepar Michael DELIQUE » 22 Juil 2005 à 17:39

Code : Tout sélectionner
Public Function ProperCase_LS(Byval Source As String, Byval nbFirstWord As Integer) As String
   
   ' Source chaine de texte a traiter
   ' nbFirstWord : true ne traite que le premier mot, false traite tous les mots
   
   Dim Char As String
   Dim i As Long
   Dim nbMajuscule As Integer
   
   On Error Goto ErreurHandle
   
   If Trim(Source) = "" Then
      ProperCase_LS = Source
   End If
   
   ProperCase_LS = ""
   Char = ""
   
   Select Case nbFirstWord
     
   Case True
      nbMajuscule = False
      For i = 1 To Len(Source)
         Char = Mid(Source,i,1)
         If nbMajuscule = False Then
            If Char Like "*[a-z,A-Z]*" Then 'Champ pouvant être mis en majuscule
               ProperCase_LS = ProperCase_LS+Ucase(Char)
               nbMajuscule = True
            Else
               ProperCase_LS = ProperCase_LS+lcase(Char)
            End If
         Else
            ProperCase_LS = ProperCase_LS+lcase(Char)
         End If
         Char = ""
      Next
      i=0
     
   Case False
      nbMajuscule = True
      For i = 1 To Len(Source)
         Char = Mid(Source,i,1)
         Select Case Char
         Case " ","-" 'liste des champ derriere lesquel on peut mettre en majuscule
            ProperCase_LS = ProperCase_LS+Char
            nbMajuscule = True
         Case Else
            If nbMajuscule = True Then
               If Char Like "*[a-z,A-Z]*" Then 'Champ pouvant être mis en majuscule
                  ProperCase_LS = ProperCase_LS+Ucase(Char)
                  nbMajuscule = False
               Else
                  ProperCase_LS = ProperCase_LS+lcase(Char)
               End If
            Else
               ProperCase_LS = ProperCase_LS+lcase(Char)
            End If
         End Select
         Char = ""
      Next   
      i=0
   Case Else
      ProperCase_LS = Source
      Exit Function
   End Select
   
   Exit Function
ErreurHandle:
   Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"   ProperCase_LS =  ""
   Exit Function
End Function
Dernière édition par Michael DELIQUE le 21 Fév 2008 à 13:30, édité 2 fois.
Avatar de l’utilisateur
Michael DELIQUE
Administrateur
Administrateur
 
Message(s) : 12183
Inscrit(e) le : 16 Déc 2004 à 10:36
Localisation : Paris/Cergy

Messagepar Michael DELIQUE » 21 Fév 2008 à 13:29

Une version un poil plus ligth

Code : Tout sélectionner
Public Function ProperCase_LS(Byval Source As String) As String
   
   ' Source chaine de texte a traiter
   
   On Error Goto ErreurHandle
   
   If Trim(Source) = "" Then
      ProperCase_LS = Source
   End If
   
   ProperCase_LS = Strconv(Source, 3)
   
   Exit Function
ErreurHandle:
   Msgbox "("+Structure_Log+" : "+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   ProperCase_LS = ""
   Exit Function
End Function
Cordialement

Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN
Avatar de l’utilisateur
Michael DELIQUE
Administrateur
Administrateur
 
Message(s) : 12183
Inscrit(e) le : 16 Déc 2004 à 10:36
Localisation : Paris/Cergy

Messagepar oguruma » 23 Fév 2008 à 09:33

pn appelle cela un "code zippé" :lol:
Bien à vous

http://www.dominoarea.org/oguruma/

Les téléphones PORTABLES dans les TGV y en a MARRRE de ces voyageurs qui ne respectent pas les autres ! ARRET DES PORTABLES SVP - Merci

Fumeurs ! respectez les non fumeurs !!!
Fumeurs ! respectez la loi de février 2007 et les lieux publics !!! (ie. hall de gares)
Avatar de l’utilisateur
oguruma
Super V.I.P.
Super V.I.P.
 
Message(s) : 4086
Inscrit(e) le : 16 Déc 2004 à 08:50
Localisation : LILLE


Retour vers Chaines de caractères