VBS et Expressions Régulières

VBS et Expressions Régulières - VB/VBA/VBS - Programmation

Marsh Posté le 07-08-2017 à 18:45:46    

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 :
  1. Option Explicit
  2. Dim replacement
  3. Dim regEx: Set regEx = New RegExp  ' Create a regular expression.
  4. Dim myString: myString = "CAke, and grief COUNSELING"
  5. regEx.Pattern = "\b\w+\b"  ' this pattern matches each single word
  6. regEx.Global = True       ' Set the scope to Global
  7. Set replacement = getRef("Capitelize" )
  8. MsgBox regEx.Replace(myString, replacement)
  9. ' This results in: "Cake, And Grief Counseling"
  10. ' We need to create a function of course with the same name and three parameters
  11. ' 1. singleMatch : the string that matched to the pattern
  12. ' 2. position : the position the singlematch string was found
  13. ' 3. fullString : the full string (same as 'myString' in this case) without _any_ replacements
  14. Function Capitelize(singleMatch, position, fullString)
  15.   ' Capitelize returns the string singleMatch changed with the first character
  16.   ' in uppercase and all others in lowercase
  17.   Capitelize = UCase(Left(singleMatch, 1)) & LCase(Mid(singleMatch, 2))
  18. End Function

Reply

Marsh Posté le 07-08-2017 à 18:45:46   

Reply

Marsh Posté le 12-08-2017 à 13:59:09    

Pour ceux que ça intéresse (s'il y en a !), j'ai trouvé des explications concernant les "Replacement Functions" en JScript, VBScript et VBA ici :  
https://msdn.microsoft.com/en-us/library/ms974619.aspx

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed