[JAVA]Parser une list

Résolu/Fermé
Chouk12 Messages postés 116 Date d'inscription mercredi 2 juillet 2008 Statut Membre Dernière intervention 6 août 2010 - 23 juil. 2009 à 08:59
Chouk12 Messages postés 116 Date d'inscription mercredi 2 juillet 2008 Statut Membre Dernière intervention 6 août 2010 - 23 juil. 2009 à 11:16
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.
A voir également:

5 réponses

Archeus01 Messages postés 1572 Date d'inscription mercredi 3 octobre 2007 Statut Membre Dernière intervention 9 juin 2022 452
23 juil. 2009 à 09:01
Bonjour,
Tu peux faire ça avec les regex.
1
Archeus01 Messages postés 1572 Date d'inscription mercredi 3 octobre 2007 Statut Membre Dernière intervention 9 juin 2022 452
23 juil. 2009 à 09:09
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
Chouk12 Messages postés 116 Date d'inscription mercredi 2 juillet 2008 Statut Membre Dernière intervention 6 août 2010 10
23 juil. 2009 à 09:03
Mais en parcourant la list?
0
Chouk12 Messages postés 116 Date d'inscription mercredi 2 juillet 2008 Statut Membre Dernière intervention 6 août 2010 10
23 juil. 2009 à 09:11
je vais étudier ça,
merci pour tes réponses rapides :)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Chouk12 Messages postés 116 Date d'inscription mercredi 2 juillet 2008 Statut Membre Dernière intervention 6 août 2010 10
23 juil. 2009 à 11:16
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