I have an assignment where I have to sort a phone list by name. I have the following code. I know it's a mess and there are some things missing but it's what I got for now. Some variables are in Portuguese but I'll make my best to make it understandable. This is a different case where I am not allowed to use LINQ's or lists
static void Main(string[] args)
{
string file= "nomes.txt";
string[] text = File.ReadAllLines(file);
// Reads line by line
for (int i = 0; i < text.Length; i++)
{
string line = text[i];
for (int j = 0; j < line.Length; j++)
{
if (char.IsWhiteSpace (line [j-1]) == true)
{
string[] palavra = line.Split(',');
if (char.IsDigit(line [j]) == true)
{
string[] nr = line.Split('-');
Console.WriteLine(line);
}
}
}
}
Console.ReadKey();
}
File looks like this:
Joaquim Lopes da Silva 932 000 999
Maria da Conceição Granja 91 384 75 34
Herculano Lopes Vieira 253334556
Expected output:
Silva, Joaquim Lopes da - 932 000 999
Granja, Maria da Conceição - 913 847 534
Vieira, Herculano Lopes - 253 334 556