Bonjour,
j'ai un fichier texte dont je dois extraire differentes phrases, cela fonctionne pour la plusprt ou je fait un split:
présentation :
Docnid: 19395574
Date de création: 14/10/2008
Type: ambassade/transmission d'infos
Motivation:
double
je recupere 19395574, ambassade/transmissions d'infos
mais j'arrive pas a recuperer 'double'
car un split ( : ) apres motivation est blanc, il me faut lire la ligne apres.
quelqu'un peut m'aider
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 private void btTri_Click(object sender, EventArgs e) { string ph1 = "Docnid:"; string ph2 = "Type"; string ph3 = "Motivati"; string[] valeurs; //tableau des données a stocker en BD string ligne; //ligne courante du fichier string temp = ""; //variable temporaire qui stocke les données StreamReader st = new StreamReader("c:\\temp\\mail.txt", System.Text.Encoding.Default); //stream du fichier while ((ligne = st.ReadLine()) != null) { if (System.Text.RegularExpressions.Regex.IsMatch(ligne, ph1, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { valeurs = ligne.Split(':'); temp = valeurs[1]; } else if (System.Text.RegularExpressions.Regex.IsMatch(ligne, ph2, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { valeurs = ligne.Split(':'); temp = temp + " ; " + valeurs[1]; } else if(System.Text.RegularExpressions.Regex.IsMatch(ligne, ph3, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) { // ligne.Trim(); //ligne.Split(Environment.NewLine.ToCharArray()); temp = temp + ";" + ligne.ToString(); MessageBox.Show(temp); } } }
Partager