Por
Saiyine
el 2005-07-01 00:21:00 - Secciones: - Enlace permanente: 438
Hoy en la sección de c sharp os propongo un ejemplo bastante más complejo que los anteriores: un objeto que emula un grep con expresiones regulares.
En particular, queria curiosear en el contenido de un fichero mbox lleno de correo basura, y ver si los email se repetian: fácil.
using System; using System.IO; using System.Text.RegularExpressions; class TGrep{ public static void Main(string[] args){ TGrep tg = new TGrep("Return-Path: <(.*@.*)>"); tg.ApplyToFiles(args[0]); } Regex re; TGrep(string pattern){ re = new Regex(pattern); } void ApplyToFiles(string fPattern){ string[] fNames = Directory.GetFiles(".", fPattern); foreach (string fName in fNames ) { StreamReader sr = null; try{ sr = new StreamReader( new BufferedStream( new FileStream( fName, FileMode.Open))); string line = ""; int lCount = 0; while((line = sr.ReadLine()) != null){ lCount++; if (re.IsMatch(line)){ System.Console.WriteLine("{0}", re.Match(line).Groups[1].ToString()); } } }finally{ sr.Close(); } } } }
Otras entradas de la web que podrian interesarte:
. . .
. . .
. . .
. . .
Varios ejemplos de lo que buscaban visitantes recientes:
. . .
Página web ©2001-2010 Saiyine generada en s, con 4639596 visitas en total, hoy (de un total de 0 previstas).
. . .