ljoli
Messages postés7Date d'inscriptionvendredi 12 décembre 2008StatutMembreDernière intervention28 juillet 2010
-
19 juil. 2010 à 15:42
ljoli
Messages postés7Date d'inscriptionvendredi 12 décembre 2008StatutMembreDernière intervention28 juillet 2010
-
28 juil. 2010 à 10:18
Bonjour,
Je voudrais pouvoir extraire des données d'un fichier CSV sous cette forme:
1 2
3 5
6 7
8 9
11 12
Par exemple je veux la valeur "8" de ce fichier.
Je travaille avec visual studio 2008 sous WPF. Voilà ce que j'ai déjà fait :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;
using System.Windows.Threading;
using System.IO;
namespace CSV file
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
///
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
InitializeChart();
}
StreamReader fichier_csv = File.OpenText("C:\\Users\\\\testone.csv");
int i;
while (fichier_csv.Peek() >= 0)
{
string ligne = fichier_csv.ReadLine();
string[] ensemble = ligne.Split(';');
string[] val = ligne.Split('\t');
MessageBox.Show( val[0] );
}
}
}
}
cs_LeCygne
Messages postés1Date d'inscriptionmardi 22 mai 2007StatutMembreDernière intervention28 juillet 2010 28 juil. 2010 à 10:02
Bonjour,
Personnellement, j'ai du mal à comprendre ta question.
Je vois dans ton code une boucle qui lit toutes les lignes d'un fichier, et qui affiche, pour chacune d'elles, dans un MessageBox la première valeur qu'elle contient.
Si tu veux la huitième valeur de ta ligne, elle est dans "val[7]" (A condition que ta ligne contienne huit champs).
ljoli
Messages postés7Date d'inscriptionvendredi 12 décembre 2008StatutMembreDernière intervention28 juillet 2010 28 juil. 2010 à 10:18
Merci d'avoir répondu.
C'est vrai que le code n'est pas tout à fait correct.
Voici quelques chose de mieux:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;
using System.Windows.Threading;
using System.IO;
namespace WpfApplication11
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
StreamReader fichier_csv = File.OpenText("C:\\Users\\ljoly\\testone.csv");
while (fichier_csv.Peek() >= 0)
{
string ligne = fichier_csv.ReadLine();
string[] ensemble = ligne.Split(';');
string[] val = ligne.Split('\t');
MessageBox.Show(val[7]);
}
}
}
}
Moi, je veux afficher une valeur précise du fichier CSV. Ce que tu propose "val[7]" me fait une exception