Yule35240
-
Modifié par Yule35240 le 19/08/2014 à 21:03
jordane45
Messages postés38138Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention17 avril 2024
-
19 août 2014 à 21:44
Bonjour,
Je cherche comment récupérer l'IP contenue de le code source d'un Email.
Pour cela j'utilise le code suivant:
Option Explicit On
Public Class Form1
Private Sub Web_StatusTextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Web.StatusTextChanged RichTextBox2.Clear() RichTextBox2.Text = Web.DocumentText Timer1.Start() End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Dim value1 As Integer = CInt(Int((255 * Rnd()) + 1)) Dim value2 As Integer = CInt(Int((255 * Rnd()) + 1)) Dim value3 As Integer = CInt(Int((255 * Rnd()) + 1))
Dim index As Integer = 0 While (index < RichTextBox2.Text.LastIndexOf("[" & value1 & ".")) RichTextBox2.Find("[" & value1 & ".", index, RichTextBox2.TextLength, RichTextBoxFinds.None) RichTextBox2.SelectionBackColor = Color.LightCoral RichTextBox2.SelectionColor = Color.White index = RichTextBox2.Text.IndexOf("[" & value1 & ".", index) + 1 End While
Dim index1 As Integer = 0 While (index1 < RichTextBox2.Text.LastIndexOf("." & value2 & ".")) RichTextBox2.Find("." & value2 & ".", index1, RichTextBox2.TextLength, RichTextBoxFinds.None) RichTextBox2.SelectionBackColor = Color.LightCoral RichTextBox2.SelectionColor = Color.White index1 = RichTextBox2.Text.IndexOf("." & value2 & ".", index1) + 1 End While
Dim index2 As Integer = 0 While (index2 < RichTextBox2.Text.LastIndexOf("." & value3 & "]")) RichTextBox2.Find("." & value3 & "]", index2, RichTextBox2.TextLength, RichTextBoxFinds.None) RichTextBox2.SelectionBackColor = Color.LightCoral RichTextBox2.SelectionColor = Color.White index2 = RichTextBox2.Text.IndexOf("." & value3 & "]", index2) + 1 End While End Sub
End Class
Mon code n'est pas propre du tout, comment peut on faire à l'aide des expressions régulières pour obtenir le même résultat?
jordane45
Messages postés38138Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention17 avril 2024344 19 août 2014 à 21:12
Visual Basic... ok.. mais ... VB6 ou VB.net ?? (je pense que c'est du .net.. mais bon.. je vais attendre ta réponse pour déplacer le sujet au BON ENDROIT )
Voici ce que tu aurais pu trouver ICI :VB.NET+regex
VB.NET Code Example:
Imports System.Text.RegularExpressions
Module Module1
Sub Main()
Dim sourcestring as String = "replace with your source string"
Dim re As Regex = New Regex("(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",RegexOptions.Multiline)
Dim mc as MatchCollection = re.Matches(sourcestring)
Dim mIdx as Integer = 0
For each m as Match in mc
For groupIdx As Integer = 0 To m.Groups.Count - 1
Console.WriteLine("[{0}][{1}] = {2}", mIdx, re.GetGroupNames(groupIdx), m.Groups(groupIdx).Value)
Next
mIdx=mIdx+1
Next
End Sub
End Module