Bonjour,
j'arrive pas à avoir la position du mot en recherchent du mot a avec File.ReadAllLines :
ça me donne a la sortie du richtextbox1:
Ligne 1 : a
Ligne 1 : a
Ligne 1 : a
exemple :
ligne 1 : a ,ligne 4 : a , ligne 8 : aa
b
c
a
g
h
b
a
c
g
k
le code :
pouvez-vous m'aider à avoir la ligne du mot a à recherchent avec File.ReadAllLines? merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 For Each line As String In File.ReadAllLines(filepath) Dim index As List(Of Integer) = counter(line, TextBox1.Text) If index.Count > 0 Then RichTextBox1.AppendText(String.Format("Ligne {0} : {1} {2}", index.Count, TextBox1.Text, Environment.NewLine)) End If Next Private Function counter(fichier As String, mot As String) As List(Of Integer) Dim positions As New List(Of Integer) Dim index As Integer = 0 Dim words As String() = fichier.Split(New String() {Environment.NewLine, " "}, StringSplitOptions.RemoveEmptyEntries) For Each word As String In words If String.Compare(word, mot, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.CompareOptions.IgnoreCase) = 0 Then positions.Add(index) index += 1 End If Next Return positions End Function
Partager