pos = Me.TextBox1.Text.IndexOf(mot) 'si pos = -1 le mot n'est pas dans le textbox.text
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox1.Text = "CODES SOURCES.COM" End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Console.WriteLine(MidStr(TextBox1.Text, "CO", ".COM")) '-> retourne bien "DES SOURCES" End Sub 'http://www.codyx.org/snippet_recuperer-chaine-inconnue-placee-entre-deux-chaines-connues_334.aspx#1046 Private Function MidStr(ByVal Expression As String, ByVal sLeft As String, ByVal sRight As String, Optional ByVal iStart As Integer = 0) As String Dim iPosL As Integer = Expression.IndexOf(sLeft, iStart) If iPosL > -1 Then Dim iPosR As Integer = Expression.IndexOf(sRight, iPosL + sLeft.Length) If iPosR = -1 Then 'pas le caractère de fin, on prend la chaîne complète iPosR = Expression.Length - iPosL - sLeft.Length sRight = String.Empty End If Return Expression.Substring(iPosL + sLeft.Length, iPosR - iPosL - sLeft.Length) End If Return String.Empty End Function