using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ContadorFilasColumnas
{
public partial class Form1 : Form
{
public string strFileName = "";
public string linea;
public StreamReader StreamReader1;
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*";
openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory();
openFileDialog1.Title = "Seleccione un archivo";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
strFileName = openFileDialog1.FileName;
textBox1.Text = strFileName;
}
}
public void button2_Click(object sender, EventArgs e)
{
StreamReader1
= new StreamReader
(strFileName
); int ncol = 0;
int nfila = 0;
textBox2.Text = "";
string s ;
char[] arrayChar
= new char[10000];
while ((linea = StreamReader1.ReadLine()) != null)
{
//verificar si cada elemento de la línea es el caracter "a"
//textBox2.Text+= linea;
nfila++;
s = linea;
arrayChar = s.ToCharArray();
for (int i = 0; i < arrayChar.Length;i++ )
{
ncol++;
if (arrayChar[i] == Convert.ToChar(caracter.Text)) {
textBox2.Text+= "Caracter encontrado en fila " + nfila + " y columna " + ncol + "\r\n";
}
//textBox2.Text += arrayChar[i] + "\n\r";
}
}
}
public void button3_Click(object sender, EventArgs e)
{
StreamReader1
= new StreamReader
(strFileName
); char caracter2 = 'A';
int contador1=0;
int contador2=0;
char[] delimi= {',',':',' ','|','.'};
char[] arrayChar
= new char[10000]; string s;
textBox3.Text = "";
s = linea;
if (s == null )
{
textBox3.Text="Error no existe el archivo";
}
else
{
while ((s = StreamReader1.ReadLine()) != null)
{
arrayChar = s.ToCharArray();
for (int i = 0; i < arrayChar.Length; i++)
{
if((caracter2==delimi[i])||(caracter2==Convert.ToChar("/t"))||(caracter2==Convert.ToChar("/n")))
contador1++;
}
if((caracter2==Convert.ToChar(delimi))&&(caracter2==Convert.ToChar("/t"))&&(caracter2==Convert.ToChar("/n")))
contador2++;
}
textBox3.Text+="En el archivo hay: "+contador1+" delimitadores, y "+ contador2+" caracteres";
}
}
}
}