[JAVA]Parser une list

Résolu
Chouk12 Messages postés 124 Statut Membre -  
Chouk12 Messages postés 124 Statut Membre -
Bonjour,

Je suis entrain de faire une méthode qui a pour but de parser un fichier de log et d'extraire chaque log en le mettant en base.
Tout d'abord je "lis le fichier log" et le place dans une liste ligne par ligne.

Sachant que c'est log ne font pas toujours une seule ligne mais commence toujours pas une date du type "dd/mm/yyyy hh/mm/ss" J'aimerais maintenant parser ma liste pour en extraire les logs.

Auriez vous une idée de comment je puisse procéder?

Merci par avance.

--
Google est Ton meilleur ami, toujours la pour toi ;)
Configuration: Win XP PRO / 
Pross : Intel core 2 duo E6660
Grph : Nvida Geforce 9800 GT
Mem : 2 Go dual channel ddr2

5 réponses

  1. Archeus01 Messages postés 1566 Date d'inscription   Statut Membre Dernière intervention   455
     
    Bonjour,
    Tu peux faire ça avec les regex.
    1
  2. Archeus01 Messages postés 1566 Date d'inscription   Statut Membre Dernière intervention   455
     
    La fonction split avec les expressions régulères.

    split

    public String[] split(String regex,
    int limit)

    Splits this string around matches of the given regular expression.

    The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

    The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

    The string "boo:and:foo", for example, yields the following results with these parameters:

    Regex Limit Result
    : 2 { "boo", "and:foo" }
    : 5 { "boo", "and", "foo" }
    : -2 { "boo", "and", "foo" }
    o 5 { "b", "", ":and:f", "", "" }
    o -2 { "b", "", ":and:f", "", "" }
    o 0 { "b", "", ":and:f" }

    An invocation of this method of the form str.split(regex, n) yields the same result as the expression

    Pattern.compile(regex).split(str, n)

    Parameters:
    regex - the delimiting regular expression
    limit - the result threshold, as described above
    Returns:
    the array of strings computed by splitting this string around matches of the given regular expression
    Throws:
    PatternSyntaxException - if the regular expression's syntax is invalid
    Since:
    1.4

    extrait de https://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split(java.lang.String,%20int)

    sauf qu'a la place des : tu mets ta regex pour détecter une date.
    1
  3. Chouk12 Messages postés 124 Statut Membre 10
     
    Mais en parcourant la list?
    0
  4. Chouk12 Messages postés 124 Statut Membre 10
     
    je vais étudier ça,
    merci pour tes réponses rapides :)
    0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. Chouk12 Messages postés 124 Statut Membre 10
     
    Voila j'ai réussi à écrire ma méthode.
    Je suis passé uniquement pas les regex et ca à l'air d'être bon ^^

    Merci beaucoup pour tes réponses.
    0