
How's YOUR wife and MY kids doing? [?]
Añademe a tus favoritos!
Contacto
Post al azar
RSS
BUSCAR
Mapa de la web
el 2005-07-01 00:21:00 - Secciones: - Enlace permanente: 438Hoy 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(); } } } }
Saiyine recommends the easiest way to earn money with your web: get paid just by having some links! Click this button to check it out.
