jpl38 | Bonjour à tous.
J'essaie de comprendre le fonctionnement d'un scrit VBS, trouvé ici : http://automated-chaos.blogspot.fr [...] place.html
Il met en majuscule la première lettre des mots de la chaine myString, les autres en minuscules.
Il utilise les expressions régulières disponibles en VBS, et la fonction getRef pour renvoyer une référence à la fonction Capitelize.
Voici les points sur lesquels je nage :
1) La fonction Capitelize a trois paramètres, mais n'en utilise qu'un. A quoi servent les deux autres ? Si j'en supprime un, j'ai un message d'erreur.
2) Dans la ligne MsgBox etc., où trouve-t-on les paramètres à passer à Capitelize ?
Si quelqu'un peut éclairer ma lanterne, merci d'avance, je suis preneur.
Code :
- Option Explicit
- Dim replacement
- Dim regEx: Set regEx = New RegExp ' Create a regular expression.
- Dim myString: myString = "CAke, and grief COUNSELING"
- regEx.Pattern = "\b\w+\b" ' this pattern matches each single word
- regEx.Global = True ' Set the scope to Global
- Set replacement = getRef("Capitelize" )
- MsgBox regEx.Replace(myString, replacement)
- ' This results in: "Cake, And Grief Counseling"
- ' We need to create a function of course with the same name and three parameters
- ' 1. singleMatch : the string that matched to the pattern
- ' 2. position : the position the singlematch string was found
- ' 3. fullString : the full string (same as 'myString' in this case) without _any_ replacements
- Function Capitelize(singleMatch, position, fullString)
- ' Capitelize returns the string singleMatch changed with the first character
- ' in uppercase and all others in lowercase
- Capitelize = UCase(Left(singleMatch, 1)) & LCase(Mid(singleMatch, 2))
- End Function
|
|