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 strFileName2 = "";
public string linea;
public string linea2;
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
); textBox3.Text = "";
string s;
int delimitadores = 0;
int tokens = 0;
char[] arrayChar
= new char[10000]; char[] delimi= {',',':',' ','|','.'};
while ((linea = StreamReader1.ReadLine()) != null)
{
//verificar si cada elemento de la línea es el caracter "a"
//textBox2.Text+= linea;
s = linea;
arrayChar = s.ToCharArray();
for (int i = 0; i < arrayChar.Length; i++)
{
if (arrayChar[i] == Convert.ToChar(delimi) ||(arrayChar[i]==Convert.ToChar("/t"))||(arrayChar[i]==Convert.ToChar("/n")))
{
delimitadores++;
}
if (arrayChar[i] != Convert.ToChar(delimi) || (arrayChar[i] != Convert.ToChar("/t")) || (arrayChar[i] != Convert.ToChar("/n")))
{
tokens++;
}
textBox3.Text = "Hay"+delimitadores+" delimitadores y "+tokens+" tokens";
}
}
}
}
}