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

VB.NET Discussion :

Une portion d'un fichier texte


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    34
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 34
    Par défaut Une portion d'un fichier texte
    Salutations tout le monde

    voilà, je cherche à faire un bdd access à partir d'un fichier texte qui contient des infos Mame

    pour la BDD, la lecture de fichiers, tout est OK

    Sachant que c'est une boucle de renseignements, je ne vais prendre ici qu'une partie du fichier texte

    je passe par ceci pour la lecture :
    Code VB.NET : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Dim sr As New IO.StreamReader(fichierselectionne)
    Dim ligne As String
    While sr.Peek <> -1
    ligne = sr.ReadLine()
    '.......
    End While

    je voudrais récupérer une portion de ce qu'il y a ci dessous, comprise (et non barrée) entre le "Game Filename" (à ne pas garder mais bon, ce serait pas trop grave à enlever) et "- TECHNICAL -"

    *#*#*#*
    ************************************************************
    *#*#*#*
    Game: '88 Games
    CRC: 429785DB
    Platform: Mame
    Genre: Sports / Track & Field
    Release Year: 1988
    Developer: Konami
    Publisher: Konami
    Game Filename: 88games

    Go for the gold in Konami's newest kit, '88 Games. Feel the thrill of competition as you test your Olympic skills against other world-class athletes. Bronze or silver medals are not good enough - you are going for the gold! However, you must at least qualify in each event in order to compete in the next event. Get pumped up to compete in the following events :
    * 100m Dash : Race against the other athletes as well as the clock. This is just a warm-up compared to the events to come.
    * Long Jump : Player dashes to the line, leaps, and propels his body as far as he is able. The player controls the speed and angle of the jump.
    * 400m Relay (Qualifying Heat) : Speed and timing are crucial in this event. Player must coordinate the baton hand-off perfectly for the best qualifying time.
    * Skeet Shooting : Player can aim left and right at the clay pigeons and must prove that he is a sure shot. A chance for bonus points is given for excellent marksmanship.
    * 110m Hurdles : Player sprints down the track, timing his jumps perfectly to clear all of the hurdles and reach the finish line in time.
    * Archery : This is a trial of the player's proficiency in using a bow and arrow. The player can decide the direction and force of the wind, which will help in demonstrating his skill as a sharpshooter.
    * Javelin Throw : The player darts to the line and throws the javelin with all his might. The player controls the height of the javelin.
    * High Jump : Another test of speed and strength as the player runs to the line and hurls his body over the bar. The player can control his angle above the bar.
    * 400m Relay - The Final Race : The final test of physical training as the player faces the challenging relay again.
    GO FOR THE GOLD!

    - TECHNICAL -
    Game ID : GX861
    Main Board Number : PWB351171A
    Rom Board Number : PWB350782



    Sachant que :
    - le mot - TECHNICAL - est toujours présent mais pas toujours la portion à garder (des fois y'a rien...)
    - la partie à garder peut varier de 1 à plusieurs lignes
    - ce qui suit - TECHNICAL - ne m'interesse pas, je le sauterai pour passer à l'enregistrement suivant...

    Je pensais que c'était une lecture ligne par ligne, mais lors de différents tests, j'ai eu des choses bizarres, alors si quelqu'un a une idée...

    Merci d'avance, bonne journée

  2. #2
    Membre Expert Avatar de mactwist69
    Homme Profil pro
    Développement VB.NET
    Inscrit en
    Janvier 2007
    Messages
    1 707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : Développement VB.NET
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 707
    Par défaut
    Bonjour,

    La méthode semble correct (au vue de la problématique en tout cas).

    Il faudra bien lire ligne par ligne, car c'est là dessus que tu feras tes tests.
    Donc il faut une boucle de lecture :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    While sr.Peek <> -1
    ligne = sr.ReadLine()
    '.......
    End While
    Et maintenant il faut faire le boulo du développeur : faire l'algorithme pour résoudre ton problème : ne récupérer que les lignes qui t'intéresse.

    On va te donner des conseils, mais pour ce genre de cas, à mon avis, tu va devoir le faire, et le refaire, surtout si tu as des cas particuliers (genre la ligne TECHNICAL qui manque) jusqu'à ce que ça marche pour tous les cas particuliers que nous ne connaissons pas.

    Sur la méthodologie, il n'y aura pas un développeur qui fera la même chose que l'autre, ça dépends de la logique de chacun. Pour ma part par exemple, j'utiliserai un Boolean pour Activer/Desactiver le récupération de ligne ou pas :

    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
     
    Dim GetLine as Boolean = False
     
    While sr.Peek <> -1
     
        ligne = sr.ReadLine()
     
        If TestMaLigneQuiContientGameFilename Then 
            'Fonction qui t'indique que tu es sur la ligne GameFileName, alors on active la récupération pour la ligne suivante
            GetLine = True
        ElseIf TestMaLigneQuiContientTechnical Then
            'Fonction qui t'indique que tu es sur la ligne TECHNICAL, alors on desactive la récupération pour la ligne suivante
            GetLine = False
        Else
            'Si pas de ligne particulière on regarde si on doit récupérer la ligne ou pas
            If GetLine Then
                RecupereMaLigne (ligne)
            EndIf
        End If
    End While
    Mais déjà, ce code à un problème : Si il n'y a pas la ligne qui contient TECHNICAL, alors il écrira l'entête que tu ne souhaites pas du jeu suivant... D'où, il faut que tu trouves des règles plus certaines ou que tu prévois plus de cas particuliers !
    Il faudrait par exemple tester la première ligne d'entête (qui contient "Game:"), si tu arrives à cette ligne est que GetLine est à True, alors tu le passes à False, car ça voudra dire qu'il n'y avait pas technical etc...

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    34
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 34
    Par défaut
    Salut mactwist69
    oui, j'ai bien pigé le boulot algorithmique à faire, je voulais juste savoir pendant que je testais plusieurs méthodes si quelqu'un connaissait par hasard le moyen de la faire plus rapidement, une méthode permettant de garder le texte compris entre 2 séparateurs string par exemple...
    Merci

  4. #4
    Membre Expert Avatar de mactwist69
    Homme Profil pro
    Développement VB.NET
    Inscrit en
    Janvier 2007
    Messages
    1 707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : Développement VB.NET
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 707
    Par défaut
    Il n'y aurait plus besoin de nous sinon !!

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    34
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 34
    Par défaut solution
    Bon, voici la réponse pour ceux que ça intéresse :

    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
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
     
     
        Dim synopsis, game, crc, platform, genre, year, developer, publisher, filename As String
        Dim arretlecture As Boolean
    Dim sr As New IO.StreamReader(fichierselectionne)
                    Dim ligne As String
                    While sr.Peek <> -1
                        ligne = sr.ReadLine()
     
                        Select Case True
                            Case ligne.Contains("Game:")
                                champs = ligne.Split(":")
                                game = (champs(1).ToString())
     
                            Case ligne.Contains("CRC:")
                                champs = ligne.Split(":")
                                crc = (champs(1).ToString())
     
                            Case ligne.Contains("Platform:")
                                champs = ligne.Split(":")
                                platform = (champs(1).ToString())
     
                            Case ligne.Contains("Genre:")
                                champs = ligne.Split(":")
                                genre = (champs(1).ToString())
     
                            Case ligne.Contains("Release Year:")
                                champs = ligne.Split(":")
                                year = (champs(1).ToString())
     
                            Case ligne.Contains("Developer:")
                                champs = ligne.Split(":")
                                developer = (champs(1).ToString())
     
                            Case ligne.Contains("Publisher:")
                                champs = ligne.Split(":")
                                publisher = (champs(1).ToString())
     
                            Case ligne.Contains("Game Filename:")
                                champs = ligne.Split(":")
                                filename = (champs(1).ToString())
     
                            Case ligne.Contains("*#*#*#*")
                                synopsis = synopsis
     
                            Case ligne.Contains("************************************************************")
                                MsgBox(game + " " + filename + " " + synopsis)
                                'requete d'insertion ??
                                synopsis = ""
                                arretlecture = False
     
                            Case ligne.Contains("- TECHNICAL -")
                                arretlecture = True
     
                            Case Else
                                If arretlecture = True Then
                                    synopsis = synopsis
                                Else
                                    synopsis = synopsis + ligne
                                End If
     
     
                        End Select
     
                    End While

    Sachant que les enregistrements sont stockés de cette manière dans le fichier texte :

    *#*#*#*
    ************************************************************
    *#*#*#*
    Game: '88 Games
    CRC: 429785DB
    Platform: Mame
    Genre: Sports / Track & Field
    Release Year: 1988
    Developer: Konami
    Publisher: Konami
    Game Filename: 88games
    Go for the gold in Konami's newest kit, '88 Games. Feel the thrill of competition as you test your Olympic skills against other world-class athletes. Bronze or silver medals are not good enough - you are going for the gold! However, you must at least qualify in each event in order to compete in the next event. Get pumped up to compete in the following events :
    * 100m Dash : Race against the other athletes as well as the clock. This is just a warm-up compared to the events to come.
    * Long Jump : Player dashes to the line, leaps, and propels his body as far as he is able. The player controls the speed and angle of the jump.
    * 400m Relay (Qualifying Heat) : Speed and timing are crucial in this event. Player must coordinate the baton hand-off perfectly for the best qualifying time.
    * Skeet Shooting : Player can aim left and right at the clay pigeons and must prove that he is a sure shot. A chance for bonus points is given for excellent marksmanship.
    * 110m Hurdles : Player sprints down the track, timing his jumps perfectly to clear all of the hurdles and reach the finish line in time.
    * Archery : This is a trial of the player's proficiency in using a bow and arrow. The player can decide the direction and force of the wind, which will help in demonstrating his skill as a sharpshooter.
    * Javelin Throw : The player darts to the line and throws the javelin with all his might. The player controls the height of the javelin.
    * High Jump : Another test of speed and strength as the player runs to the line and hurls his body over the bar. The player can control his angle above the bar.
    * 400m Relay - The Final Race : The final test of physical training as the player faces the challenging relay again.
    GO FOR THE GOLD!
    - TECHNICAL -
    Game ID : GX861
    Main Board Number : PWB351171A
    Rom Board Number : PWB350782
    Prom Stickers : A0xx
    Main CPU : KONAMI
    Sound CPU : Z80
    Sound Chips : YM2151, (2x) UPD7759
    Screen orientation : Horizontal
    Video resolution : 304 x 224 pixels
    Screen refresh : 60.00 Hz
    Palette colors : 2048
    Players : 4
    Buttons : 3, depending of the event...
    => 100m Dash : [1] Power, [2] Unused, [3] Power
    => Long Jump : [1] Power, [2] Jump, [3] Power
    => 400m Relay : [1] Power, [2] Relay, [3] Power
    => Skeet Shooting : [1] Shoot, [2] Left, [3]Right
    => 110m Hurdles : [1] Power, [2] Jump, [3] Power
    => Archery : [1] Unused, [2] Shoot, [3] Unused
    => Javelin Throw : [1] Power, [2] Shoot, [3] Power
    => High Jump : [1] Power, [2] Jump, [3] Power
    - TRIVIA -
    Released in July 1988, just in time for the 1988 Olympic games.
    On the 100m Dash event, adverts for some other Konami games can be seen in the background : "Flak Attack", "Ajax", "The Hustler" and "City Bomber".
    Default high-score :
    1 H.O 50000
    2 M.O 49500
    3 J.N 49000
    4 A.S 48500
    5 T.O 48000
    6 K.K 47500
    7 H.A 47000
    8 A.N 46500
    9 H.I 46000
    10 Y.S 45500
    11 F.S 45000
    12 K.O 44500
    Japanese releases :
    Hyper Sports Special (Konami)
    Outside Japan releases :
    '88 Games (Konami)
    Konami '88 (Konami)
    - SERIES -
    1. Track and Field (1983)
    2. Hyper Sports (1984)
    3. '88 Games (1988)
    4. Hyper Athlete (1996)
    5. Nagano Winter Olympics '98 (1998)
    6. International Track & Field 2000 (2000, Sony PlayStation)
    7. International Track & Field Summer Games (2000, Nintendo 64)
    8. New International Track & Field (2008, Nintendo DS)
    - SOURCES -
    Game's rom.
    Machine's picture.

    *#*#*#*
    ********************************************************************
    *#*#*#*
    Game: '98 NeoPri Best 44
    CRC: 94416D67
    Platform: Mame
    Genre: [Not Classified]
    Release Year: 1998
    Developer: SNK
    Publisher: SNK
    Game Filename: 98best44
    - SOURCES -
    Game's ROM.

    *#*#*#*
    ********************************************************************
    *#*#*#*
    Game: '99 The Last War
    CRC: 49A2383E
    Platform: Mame
    Genre: Shooter / Gallery
    Release Year: 1985
    Developer: Proma
    Publisher: Proma
    Game Filename: 99lstwar
    An old generation shoot'em up.
    - TECHNICAL -
    Main CPU : (2x) Z80
    Sound Chips : (2x) AY8910
    Screen orientation : Vertical
    Video resolution : 224 x 288 pixels
    Screen refresh : 60.00 Hz
    Palette colors : 256
    Players : 1
    Control : 8-way joystick
    Buttons : 2
    => [A] Shoot, [B] Shield
    - TRIVIA -
    Default high-score :
    1 50000 (Ichiban)
    2 50000 (Niban)
    3 50000 (Sanban)
    4 50000 (yonban)
    5 50000 (goban)
    Original products :
    Repulse (Sega)
    Licensed products :
    '99 The Last War (Proma)
    '99 The Last War (Kyugo)
    Bootlegs/Hacks :
    Son of Phoenix (Associated Overseas)
    - TIPS AND TRICKS -
    * Power-up : after the middle of each stage there's a helicopter (a plane on 1st stage) that drops a power-up item. So, don't destroy it till it releases the power-up. Be careful with the helicopter scrap after destroying it, it can kill you.
    * 1up player : at the 2nd and 4th stage there is a chance to pick up a 1up item : a group of blocks appears floating on the upper part of the screen, you have to shoot the blue one. You have to hit it with one shot, if you don't the blue block will turn to red.
    * Moai statues : be careful with the Moai Statues at the 6th stage (last stage). Always check if its eyes turn red, if it starts blinking it will shoot.
    - STAFF -
    Director : Shunkoh Miki
    Programmer : Tatsuya Uemura
    Character designers : Atsushi Kawaguchi, Minoru Harada, Hiroyasu Kobayashi
    Music & sound effects : ???
    - SOURCES -
    Game's rom.





    je stocke les infos que je veux avec un select
    Je choisis d'arrêter le stockage dans la variable 'synopsis' dès que je vois l'expression '- TECHNICAL -'
    je la reprends quand je croise la ligne "************************************************************"

    c'est po parfait car je m'aperçois que "- TECHNICAL -" n'est pas toujours présent, mais bon, j'vais peaufiner...

    merci

  6. #6
    Membre expérimenté
    Avatar de Kropernic
    Homme Profil pro
    Analyste / Programmeur / DBA
    Inscrit en
    Juillet 2006
    Messages
    3 932
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Belgique

    Informations professionnelles :
    Activité : Analyste / Programmeur / DBA
    Secteur : Distribution

    Informations forums :
    Inscription : Juillet 2006
    Messages : 3 932
    Par défaut
    En fait, si je comprends bien, tu dois arrêter dès que tu rencontres une ligne qui commence ET qui termine par un tiret.

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

Discussions similaires

  1. Réponses: 5
    Dernier message: 23/12/2005, 19h19
  2. Réponses: 9
    Dernier message: 16/12/2005, 15h46
  3. Réponses: 4
    Dernier message: 24/09/2005, 09h52
  4. Réponses: 4
    Dernier message: 21/06/2005, 16h45
  5. Comment faire une insertion dans un fichier texte ?
    Par Isa31 dans le forum Langage
    Réponses: 10
    Dernier message: 28/12/2004, 09h06

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