Bonjour,
j'ai trouvé quelques posts sur la méthode StreamReader pour lire un fichier.
je l'utilise, mais j'ai un problème avec les accents. je ne les retrouve pas de mon fichier original.
ce que je fais:
j'ouvre un fichier, je lis toutes les lignes et je regarde si je trouve un string dedans. si oui, j'ajoute la ligne trouvée dans un listbox.
problème: mon listbox n'a aucun accent (le caractère accentué dans le fichier ne se retrouve pas dans ma listbox).
que faire ?
voici mon code:
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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchBt.Click Dim FileToOpen, StrSearch Dim Pos, NbLine Dim objStreamReader As StreamReader Dim strLine As String FileToOpen = ROBIPERFile.Text StrSearch = SearchStr.Text Result.Items.Clear() NbLine = 0 'Pass the file path and the file name to the StreamReader constructor. objStreamReader = New StreamReader(FileToOpen.ToString) 'Read the first line of text. strLine = objStreamReader.ReadLine 'Continue to read until you reach the end of the file. Do While Not strLine Is Nothing NbLine += 1 If ((NbLine \ 200) = (NbLine / 200)) Then LineCpt.Text = "Lines parsed: " & NbLine Application.DoEvents() End If Pos = InStr(1, strLine, StrSearch) If (Pos > 0) Then Result.Items.Add(strLine) Application.DoEvents() End If strLine = objStreamReader.ReadLine Loop 'Close the file. objStreamReader.Close() LineCpt.Text = "Lines parsed: " & NbLine End Sub
merci







Répondre avec citation
Partager