'declaration generale Const CSN = "bcçdfghjklmpqstvwxz" 'dans une sub: dim Consonnas(18) as string for i = 1 to len(CSN) . Consonnas(i-1)=mid$(CSN,i,1) next
Const CSN = "b,c,ç,d,f,g,h,j,k,l,m,p,q,s,t,v,w,x,z" dim Consonnas() as string Consonnas=Split(CSN, ",")
Public Function ReplaceConsonnas(ByVal Buffer As String) As String Dim Reg As New RegExp With Reg .MultiLine = True .Global = True .IgnoreCase = True .Pattern = "am[b|c|ç|d|f|g|h|j|k|l|m|p|q|s|t|v|w|x|z]" ReplaceConsonnas = .Replace(Buffer, "@") End With End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub test_Click() chemin = App.Path & "\test.txt" Dim fichier As String Dim ligne As String Dim Canal As Byte Canal = FreeFile Open chemin For Input As #Canal While Not EOF(Canal) Line Input #Canal, ligne fichier = fichier & vbCrLf & ligne Wend Close #Canal fichier = ReplaceConsonnas(fichier) Canal = FreeFile Open chemin For Output As #Canal Print #Canal, fichier Close #Canal End Sub Public Function ReplaceConsonnas(ByVal Buffer As String) As String Dim Reg As New RegExp, Match As Match Dim Ret As String, LastStart As Long With Reg .MultiLine = True .Global = True .IgnoreCase = True .Pattern = "(am)([b|c|d|d|f|g|h|j|k|l|m|p|q|s|t|v|w|x|z])" For Each Match In Reg.Execute(Buffer) Ret = Ret & Mid$(Buffer, LastStart + 1, Match.FirstIndex - LastStart) & "@" & Match.SubMatches(1) LastStart = Match.FirstIndex + Match.Length Next Match ReplaceConsonnas = Ret & Mid$(Buffer, LastStart + 1) End With End Function
Public Function RegReplace(ByVal Buffer As String, Pattern As String, ReplaceString As String, ByVal SubsetToReplace As Integer) As String Dim Reg As New RegExp, Match As Match Dim Ret As String, LastStart As Long Dim i As Byte With Reg .MultiLine = True .Global = True .IgnoreCase = True .Pattern = Pattern For Each Match In Reg.Execute(Buffer) Ret = Ret & Mid$(Buffer, LastStart + 1, Match.FirstIndex - LastStart) For i = 0 To Match.SubMatches.Count - 1 If i <> SubsetToReplace Then Ret = Ret & Match.SubMatches(i) Else Ret = Ret & ReplaceString End If Next i LastStart = Match.FirstIndex + Match.Length Next Match RegReplace = Ret & Mid$(Buffer, LastStart + 1) End With End Function Private Sub Command1_Click() MsgBox RegReplace("le ciel est bien noir, ce soir.", "(i)(en)", ")", 1) MsgBox RegReplace("Vous trouverez surement cela très nase !", "([a|e|i|o|u|y])(s)([a|e|i|o|u|y])", "Z", 1) MsgBox RegReplace("ample , ambitieux, amour", "(am)([b|c|d|d|f|g|h|j|k|l|m|p|q|s|t|v|w|x|z])", "@", 0) End Sub