Documente Academic
Documente Profesional
Documente Cultură
NAMESPACE : System.Text.RegularExpressions
Caracteres Especiales
^ Comienzo de Cadena
\d Solo digitos
\s Solo espacios en blanco, tabs
\w Solo cadenas
{5} Longitud 5
$ Fin de Cadena
ENCODING/DECODING
NAMESPACE : System.Text.Encoding.GetEncoding
Encoding.GetBytes
EncodingInfo[] ei = Encoding.GetEncodings();
// ESCRITURA
StreamWriter swUtf7 = new StreamWriter("utf7.txt", false, Encoding.UTF7);
swUtf7.WriteLine("Hello, World!");
swUtf7.Close();
// LECTURA
StreamReader sr = new StreamReader(fn, Encoding.UTF7);
Console.WriteLine(sr.ReadToEnd());
sr.Close();
SOLUCION EJERCICIOS
/*
Practice 1
Write a console application that reads your C:\boot.ini file and displays
just the timeout.
Practice 4
Write a console application that reads the %windir%\Windows-
Update.log file, changes the date format to mm-dd-yy, and writes the output
to a
second file.
Practice 5
Write a console application with a method that reads the
%windir%\WindowsUpdate.log file and writes the output to a second file using
an encoding type provided in a parameter. Compare the file sizes of each
encoding
type.
*/
// 1.
/*
StreamReader streamReader = new
StreamReader(@"C:\Users\Carlos\Documents\Visual Studio
2005\Projects\MCTS_Testing\MCTS_Testing\Capitulo3\ArchivoBusqueda.txt");
String archivoContenido = streamReader.ReadToEnd();
Match match = Regex.Match(archivoContenido, @"%([A-Za-z0-9\-]+)%"); //
([A-Za-z0-9\-]+) : Alfanumerico
if (match.Success)
{
Console.WriteLine(match.Groups[1]);
}
else
{
Console.WriteLine("Failure");
}
*/
//4.
// StreamReader streamReader = new
StreamReader(@"C:\Users\Carlos\Documents\Visual Studio
2005\Projects\MCTS_Testing\MCTS_Testing\Capitulo3\ArchivoBusqueda.txt");
//String archivoContenido = streamReader.ReadToEnd();
//String nuevaCadena = Regex.Replace(archivoContenido, @"%([A-Za-
z0-9\-]+)%", "tomcat"); // ([A-Za-z0-9\-]+) : Alfanumerico
//Console.WriteLine(nuevaCadena);
//5.
//StreamReader streamReader = new
StreamReader(@"C:\Users\Carlos\Documents\Visual Studio
2005\Projects\MCTS_Testing\MCTS_Testing\Capitulo3\ArchivoBusqueda.txt");
//String archivoContenido = streamReader.ReadToEnd();
//StreamWriter streamWriter = new
StreamWriter(@"C:\Users\Carlos\Documents\Visual Studio
2005\Projects\MCTS_Testing\MCTS_Testing\Capitulo3\ArchivoBusqueda2.txt",
false,Encoding.BigEndianUnicode);
//streamWriter.Write(archivoContenido);
//streamReader.Close();
//streamWriter.Close();