Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication20_Practic3
- {
- class Program
- {
- public struct Person
- {
- private string fio;
- public string Fio
- {
- set
- {
- this.fio = value;
- }
- get
- {
- var fioDetaile = this.fio.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- var Name = fioDetaile[0];
- var Family = fioDetaile[1];
- var SecondName = fioDetaile[2];
- return $"{Name}' '{Family}' '{SecondName}";
- }
- }
- private int age;
- public int Age { get { return this.age; } }
- public string Email { get; private set; }
- public override string ToString()
- {
- return $"{CapitalizeAllWords(this.fio)}\t{this.age}\t{this.Email}";
- }
- public Person(string csvPerson)
- {
- var personArray = csvPerson.Split(';');
- this.fio = personArray[0];
- string z = String.Join("", personArray[1].Split(',', ' '));
- this.age = Convert.ToInt32(z);
- string y = String.Join("", personArray[2].Split(' '));
- this.Email = y;
- }
- public string CapitalizeAllWords(string s)
- {
- var sb = new StringBuilder(s.Length);
- bool inWord = false;
- foreach (var c in s)
- {
- if (char.IsLetter(c))
- {
- sb.Append(inWord ? char.ToLower(c) : char.ToUpper(c));
- inWord = true;
- }
- else
- {
- sb.Append(c);
- inWord = false;
- }
- }
- return sb.ToString();
- }
- internal string Substring()
- {
- throw new NotImplementedException();
- }
- }
- static void Main(string[] args)
- {
- //const string text = @"Иванов иван иванович; 45;[email protected]
- // Петров Петр петрович; ,76,;
- // Сидоров Сидор Сидорович; 14; еще_не_завел@qwerty.com";
- string path = @"text.txt";
- string[] TextLines = File.ReadAllText(path, Encoding.Default).Split('\n');
- // var TextLines = text.Split('\n');
- Person[] info = new Person[TextLines.Length];
- for (var i = 0; i < TextLines.Length; i++)
- info[i] = new Person(TextLines[i]);
- for (var i = 0; i < info.Length - 1; i++)
- {
- for (var j = i + 1; j < info.Length; j++)
- {
- if (info[i].Age > info[j].Age)
- {
- var temp = info[i];
- info[i] = info[j];
- info[j] = temp;
- }
- }
- }
- for (var i = 0; i < info.Length; i++)
- Console.WriteLine(info[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment