• Viernes 29 de Marzo de 2024, 07:36

Autor Tema:  Error al comparar vectores char  (Leído 1524 veces)

rogerfor

  • Miembro activo
  • **
  • Mensajes: 57
    • Ver Perfil
Error al comparar vectores char
« en: Martes 13 de Marzo de 2012, 03:04 »
0
Buenas noches, justo aquí me facilitaron un codigo que me ayudo bastante y lo he estado modificando, el problema que tengo que es que me da error de conversion a la hora que comparo un vector donde esta un archivo de texto con otro vector donde tengo varios char a comparar, no hayo que pueda ser, he probado y no lo logro solucionar, espero puedan ayudarme por favor se los agradecer mucho.

Código: C#
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace ContadorFilasColumnas
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.  
  16.         public string strFileName = "";
  17.         public string strFileName2 = "";
  18.         public string linea;
  19.         public string linea2;
  20.         public StreamReader StreamReader1;
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         public void button1_Click(object sender, EventArgs e)
  27.         {
  28.             openFileDialog1.Filter = "archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*";
  29.             openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory();
  30.             openFileDialog1.Title = "Seleccione un archivo";
  31.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  32.             {
  33.                 strFileName = openFileDialog1.FileName;
  34.                 textBox1.Text = strFileName;
  35.  
  36.             }
  37.  
  38.         }
  39.  
  40.         public void button2_Click(object sender, EventArgs e)
  41.         {
  42.             StreamReader1 = new StreamReader(strFileName);
  43.             int ncol = 0;
  44.             int nfila = 0;
  45.             textBox2.Text = "";
  46.             string s;
  47.             char[] arrayChar = new char[10000];
  48.  
  49.             while ((linea = StreamReader1.ReadLine()) != null)
  50.             {
  51.                 //verificar si cada elemento de la línea es el caracter "a"
  52.                 //textBox2.Text+= linea;
  53.                 nfila++;
  54.                 s = linea;
  55.  
  56.                 arrayChar = s.ToCharArray();
  57.                 for (int i = 0; i < arrayChar.Length; i++)
  58.                 {
  59.                     ncol++;
  60.                     if (arrayChar[i] == Convert.ToChar(caracter.Text))
  61.                     {
  62.  
  63.                         textBox2.Text += "Caracter encontrado en fila " + nfila + " y columna " + ncol + "\r\n";
  64.                     }
  65.                     //textBox2.Text += arrayChar[i] + "\n\r";
  66.                 }
  67.  
  68.  
  69.  
  70.             }
  71.  
  72.  
  73.         }
  74.  
  75.         public void button3_Click(object sender, EventArgs e)
  76.         {
  77.             StreamReader1 = new StreamReader(strFileName);
  78.             textBox3.Text = "";
  79.             string s;
  80.             int delimitadores = 0;
  81.             int tokens = 0;
  82.             char[] arrayChar = new char[10000];
  83.             char[] delimi= {',',':',' ','|','.'};
  84.  
  85.             while ((linea = StreamReader1.ReadLine()) != null)
  86.             {
  87.                 //verificar si cada elemento de la línea es el caracter "a"
  88.                 //textBox2.Text+= linea;
  89.                 s = linea;
  90.  
  91.                 arrayChar = s.ToCharArray();
  92.                 for (int i = 0; i < arrayChar.Length; i++)
  93.                 {
  94.                     if (arrayChar[i] == Convert.ToChar(delimi) ||(arrayChar[i]==Convert.ToChar("/t"))||(arrayChar[i]==Convert.ToChar("/n")))
  95.                     {
  96.                         delimitadores++;
  97.                     }
  98.                     if (arrayChar[i] != Convert.ToChar(delimi) || (arrayChar[i] != Convert.ToChar("/t")) || (arrayChar[i] != Convert.ToChar("/n")))
  99.                     {
  100.                         tokens++;
  101.                     }
  102.                     textBox3.Text = "Hay"+delimitadores+" delimitadores y "+tokens+" tokens";
  103.                 }
  104.  
  105.             }
  106.         }
  107.     }
  108. }
  109.  
  110.  

gabio2

  • Miembro MUY activo
  • ***
  • Mensajes: 402
  • Nacionalidad: mx
    • Ver Perfil
Re:Error al comparar vectores char
« Respuesta #1 en: Martes 13 de Marzo de 2012, 05:44 »
0
Podrías especificar, en que línea marca el error .....


Saludos !
@gabio87