IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Extraire 3 lignes d'un fichiers txt


Sujet :

C#

  1. #1
    Membre régulier Avatar de kazylax
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    278
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Gironde (Aquitaine)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 278
    Points : 121
    Points
    121
    Par défaut Extraire 3 lignes d'un fichiers txt
    Bonsoir,

    j'ai beau chercher dans la faq mais je trouve pas se que je veux
    voila j'ai un problème je fait un petit programme
    pour ma Guilde du jeux World of Warcraft

    Je voudrais extraire des informations qui sont dans un fichier .txt
    mettre ceci dans ma Listview mais j'y arrive pas j'ai du mal...

    le fichier contient ceci exactement
    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
     
    ## Interface: 50001
    ## Version: 11.100
    ## Title: BadBoy
    ## Notes: A light, automatic spam blocker & reporter.
    ## Notes-deDE: Automatischer Spam Blocker & Reporter.
    ## Notes-ruRU: A light, automatic spam blocker & reporter.
    ## Notes-zhCN: 一个轻巧,自动阻挡和举报垃圾信息的插件。
    ## Notes-zhTW: 一個輕量級,自動阻擋垃圾訊息與舉報的插件。
    ## Notes-koKR: A light, automatic spam blocker & reporter.
    ## Notes-frFR: Un simple anti-spam & signalement des abus.
    ## Notes-esES: Ligero bloqueador y reportador de spam automático.
    ## Notes-esMX: A light, automatic spam blocker & reporter.
    ## Notes-ptBR: Um leve bloqueador automático de spam e reportador.
    ## Notes-itIT: Un blocco spam automatico e leggero.
    ## Author: Funkydude
    ## SavedVariables: BADBOY_POPUP, BADBOY_NOREPORT
    ## X-Credits: Shadowed(API hunting), Ellipsis(remembering odd things), Anea(original SpamSentry blacklist in BadBoy v1), WoW Community(for reporting spam)
    ## X-Category: Chat/Communication
    ## X-License: All Rights Reserved
    ## X-Curse-Packaged-Version: v11.100
    ## X-Curse-Project-Name: BadBoy: Spam Blocker & Reporter
    ## X-Curse-Project-ID: bad-boy
    ## X-Curse-Repository-ID: wow/bad-boy/mainline
     
    SimpleOptions.lua
    BadBoy.lua
    Je voudrais prendre la ligne (Interface et title et Author)
    pour l'ajouter dans ma listview.

    comment je peux faire ceci s'il vous plait ?

    Merci
    cordialement,

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 37
    Points : 31
    Points
    31
    Par défaut
    Bonsoir, il suffit simplement d'utiliser StreamReader voila dans ton cas cela donne :

    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
     
            private static string GetLine(string MotCle, string path)
            {
                string result = null;
     
                using (System.IO.StreamReader reader = new System.IO.StreamReader(path))
                {
                    while (reader.EndOfStream != true)
                    {
                        string currentLine = reader.ReadLine();
                        if (currentLine.Contains(MotCle))
                            result = currentLine.Split(':')[1].TrimStart();
                    }
                }
     
                return result;
            }
     
            static void Main(string[] args)
            {
                 string path = System.IO.Path.Combine(Environment.CurrentDirectory + @"\TextFile1.txt");
     
                 string Interface = GetLine("Interface", path);
                 string Title = GetLine("Title", path);
                 string Author = GetLine("Author", path);
            }
    Cordialement Quentin.

  3. #3
    Membre régulier Avatar de kazylax
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    278
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Gironde (Aquitaine)

    Informations forums :
    Inscription : Juillet 2007
    Messages : 278
    Points : 121
    Points
    121
    Par défaut
    Ok je te remercie

    Cordialement,

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Déterminer le nombre de lignes d'un fichier [.txt]
    Par Metallic-84s dans le forum Langage
    Réponses: 2
    Dernier message: 14/03/2006, 09h34
  2. extraction d'une ligne d'un fichier txt
    Par tim69000 dans le forum VB 6 et antérieur
    Réponses: 12
    Dernier message: 19/01/2006, 15h28
  3. nbr de lignes dans un fichier txt
    Par ibtisss dans le forum Langage
    Réponses: 3
    Dernier message: 04/11/2005, 15h09
  4. Réponses: 7
    Dernier message: 29/09/2005, 10h19
  5. Extraire des lignes d'un fichier en commande bash
    Par newnew dans le forum Linux
    Réponses: 3
    Dernier message: 27/07/2004, 16h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo