Public Class Form1 Dim texte As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim liste As New List(Of String) Using r As New IO.StreamReader("mots.txt") liste.AddRange(r.ReadToEnd.Split(Environment.NewLine)) End Using texte = "BA" Dim items As List(Of String) = liste.FindAll(AddressOf Cherche) '... moins de 1 seconde End Sub Private Function Cherche(ByVal mot As String) As Boolean If mot.Contains(texte) Then Return True Else Return False End Function End Class
liste.AddRange(r.ReadToEnd.Split(New String() {Environment.NewLine}, StringSplitOptions.None))
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionton code est bon pour trouver un mot seulement
Option Strict On Public Class Form1 Dim Mots As New List(Of String) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'chargement fichier de mots Using r As New IO.StreamReader("mots.txt") Mots.AddRange(r.ReadToEnd.Split(New String() {Environment.NewLine}, StringSplitOptions.None)) End Using Dim resultats As List(Of String) = ChercherMots("SONPISOSAND") '.... resultats ici End Sub Public Function ChercherMots(ByVal Melange As String) As List(Of String) Dim motsf As New List(Of String) For Each mot As String In Mots Dim masque As String = mot For Each lettre As String In Melange If masque.Contains(lettre) Then masque = Replace(masque, lettre, "", 1, 1) End If Next If masque.Length = 0 Then motsf.Add(mot) Next 'tri par longeur de mot motsf.Sort(New clsCompare) Return motsf End Function Class clsCompare Implements IComparer(Of String) Public Function Compare(ByVal x As String, ByVal y As String) As Integer Implements System.Collections.Generic.IComparer(Of String).Compare If x.Length > y.Length Then Return -1 ElseIf x.Length = y.Length Then Return 0 Else Return 1 End If End Function End Class End Class
Private Function FindWordInList(ByVal index As Integer, ByVal permutation As String()) As List(Of String) Dim id As Integer Dim listresult As New List(Of String) For Each item In permutation id = listdico(index).BinarySearch(item) If id >= 0 Then listresult.Add(item) End If Next Return listresult End Function