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 :

Vb.net et fichier text


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2005
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Septembre 2005
    Messages : 151
    Par défaut Vb.net et fichier text
    salut
    je travail sur un fichier texte qui contient des milliers de lignes, j'arrive a l'exporter vers une table access.
    Je veux exporter que les lignes qui commence par une chaine specifique de cartactere voila 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
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
     Using monReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(cheminfichier)
                monReader.TextFieldType = FileIO.FieldType.FixedWidth
                monReader.SetFieldWidths(4, 7, 30, 2, 7, 8, 8, 1, 8, -1)
                Dim ligneCourante As String()
                Dim afficheLigCourante As String = ""
                Dim numChamp As Integer = 1
                While Not monReader.EndOfData
                    Try
                        ligneCourante = monReader.ReadFields()
                        Dim champCourant As String = String.Empty
                        objFiche = New Fiche1
                        numChamp = 1
                        For Each champCourant In ligneCourante
                            Select Case numChamp
                                Case 1
                                    objFiche.champ1 = CType(champCourant, String)
                                Case 2
                                    objFiche.champ2 = CType(champCourant, String)
                                Case 3
                                    objFiche.champ3 = CType(champCourant, String)
                                Case 4
                                    objFiche.champ4 = CType(champCourant, String)
                                Case 5
                                    objFiche.champ5 = CType(champCourant, String)
                                Case 6
                                    objFiche.champ6 = CType(champCourant, String)
                                Case 7
                                    objFiche.champ7 = CType(champCourant, String)
                                Case 8
                                    objFiche.champ8 = CType(champCourant, String)
                                Case 9
                                    objFiche.champ9 = CType(champCourant, String)
                                Case 10
                                    objFiche.champ10 = CType(champCourant, String)
                            End Select
                            'champ suivant
                            numChamp = numChamp + 1
                            afficheLigCourante = afficheLigCourante & champCourant
                            afficheLigCourante = ""
                        Next
                        Call list1(objFiche)
                        'ligne suivant
                        'MsgBox(afficheLigCourante, MsgBoxStyle.DefaultButton1)
                        'afficheLigCourante = ""
                        'DataGridView1.DataSource = liste1
                    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                        MsgBox("Ligne " & ex.Message & "non valide,sera saute....")
                    End Try
                End While
            End Using
    ce code me fait exporter toutes les ligne vers une liste apres c simple j'exporte vers table access.
    Comment faire pour extraire que les ligne qui commence par une chaine de caractere que je dois spercifié.
    merci.

  2. #2
    Membre Expert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2013
    Messages
    1 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 563
    Par défaut
    Citation Envoyé par sanfour_walhan Voir le message
    Comment faire pour extraire que les ligne qui commence par une chaine de caractere que je dois spercifié.
    Pour chaque ligne que tu reçois, tu testes si elle commence par la chaîne de caractères spécifié... Regardes du côté de String.StartWith, ou String.Left si tu connais la longueur du code de la ligne.

  3. #3
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2005
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Septembre 2005
    Messages : 151
    Par défaut
    Merci pour votre reponse
    Mais ou mettre mon code de startwith et c quoi le syntaxe?
    Merci

  4. #4
    Membre Expert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2013
    Messages
    1 563
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 563
    Par défaut
    Citation Envoyé par sanfour_walhan Voir le message
    Merci pour votre reponse
    Mais ou mettre mon code de startwith et c quoi le syntaxe?
    Merci
    Tu mets le code juste avant de faire l'export vers Access. En fait tu test si ta chaine correspond à tes besoins, si oui tu l'exportes. Si non tu fais rien.

    Et la syntaxe est très bien expliquée dans les liens que je t'ai proposé.

  5. #5
    Membre très actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Septembre 2005
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Septembre 2005
    Messages : 151
    Par défaut
    Merci pour vos explications.
    problème résolu.

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

Discussions similaires

  1. [VB.Net]Ressources fichier texte
    Par mustang-f27 dans le forum Windows Forms
    Réponses: 3
    Dernier message: 19/11/2006, 11h03
  2. [VB.NET] lecture fichier texte et détection des mots
    Par zouhib dans le forum Windows Forms
    Réponses: 25
    Dernier message: 01/06/2006, 09h12
  3. [VB.NET] Fichier text et byte()
    Par nmerydem dans le forum Windows Forms
    Réponses: 6
    Dernier message: 10/11/2004, 17h28
  4. Réponses: 2
    Dernier message: 26/05/2004, 17h53
  5. [VB.NET] Importation de fichier texte
    Par Hoegaarden dans le forum Windows Forms
    Réponses: 5
    Dernier message: 25/05/2004, 09h39

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