Hello :) Well it is a simple program in which a .txt is handled, the program has the option to enter data, print them and search ....
My problem is in the third part: Search, the data that is saved in the txt are: Password, Name and Position as follows:
123
Carlos Dayan Rodriguez Perez
Administrator
-Espacio-
234
Diego Antonio Rodriguez Perez
Programmer
-Spacio
456
Juan Camaney
Tester
-Spacio
Notice what it says -Spa- with that indicated that instead of a line break emptied every one that ends a "record" there is a space, it is because of this ......
The code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Programa1_Agenda
{
class Program
{
static StreamReader Leer;
static StreamWriter Escribir;
static void Main(string[] args)
{
int Op;
int op_1 = 0;
do
{
Console.Clear();
Console.WriteLine("AGENDA 2018\n\n");
Console.WriteLine("1) Ingresar datos\n2) Mostrar datos\n3) Buscar persona\n4) Salir\n\nTu opcion: ");
Op = int.Parse(Console.ReadLine());
if (Op == 1)
{
do
{
int DUI;
string nombre;
string puesto;
Console.Clear();
Console.WriteLine("Escribir un nuevo registro\n\n");
Escribir = new StreamWriter("Archivo_Agenda.txt", true);
//INGRESA DATOS
Console.Write("\n* Ingresar nueva clave DUI (3 Digitos enteros): ");
DUI = int.Parse(Console.ReadLine());
Escribir.WriteLine(DUI);
Console.Write("\n* Ingresar nombre completo: ");
nombre = Console.ReadLine();
Escribir.WriteLine(nombre);
Console.Write("\n* Ingresar puesto: ");
puesto = Console.ReadLine();
Escribir.WriteLine(puesto);
Console.WriteLine("\n\n");
String Cadena = Console.ReadLine();
Escribir.WriteLine(Cadena);
Escribir.Close();
Console.WriteLine("El registro se ha creado exitosamente.\n\n5) Regresar al menu principal\n6) Ingresar un nuevo usuario");
Console.Write("\nTu opcion: ");
op_1 = int.Parse(Console.ReadLine());
} while (op_1 == 6);
}
if (Op == 2)
{
string Linea;
int contador = 0;
Console.Clear();
Leer = new StreamReader("Archivo_Agenda.txt", true);
Console.WriteLine("Mostrando todos los registros:\n\n");
while((Linea = Leer.ReadLine()) != null)
{
Console.WriteLine(Linea);
contador++;
}
Leer.Close();
Console.WriteLine("\nEl registro se mostro exitosamente.\n\n5) Regresar al menu principal\n");
Console.Write("\nTu opcion: ");
op_1 = int.Parse(Console.ReadLine());
}
if (Op == 3)
{
string Linea;
int contador = 0;
string result_s;
Console.Clear();
Leer = new StreamReader("Archivo_Agenda.txt", true);
Console.WriteLine("Buscar registro por medio de clave DUI:\n\n");
Console.Write("Ingresa la clave DUI: ");
result_s = Console.ReadLine();
if((Linea = Leer.ReadLine()) == result_s)
{
do
{
Console.WriteLine(Linea);
contador++;
} while ((Linea = Leer.ReadLine()) != " ");
}
Leer.Close();
Console.WriteLine("\nEl registro se mostro exitosamente.\n\n5) Regresar al menu principal\n");
Console.Write("\nTu opcion: ");
op_1 = int.Parse(Console.ReadLine());
}
Console.ReadKey();
} while (op_1 == 5);
}
}
}
What I try to do in option 3, is that by asking for the DUI key and being detected in the file, the following data will be printed on the screen until a space is found (and this is the reason why ...)
This is done if the first record is entered: 123, and prints the correct thing:
123
Carlos Dayan Rodriguez Perez
Administrator
But if I enter any of the other 2, nothing is printed ...: (
Please help, I do not know what to do xd