Spicke

Списак

Mar 25th, 2018
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication20_Practic3
  9. {
  10.     class Program
  11.     {
  12.         public struct Person
  13.         {
  14.            
  15.             private string fio;
  16.             public string Fio
  17.             {
  18.                 set
  19.                 {
  20.                     this.fio = value;
  21.                 }
  22.                 get
  23.                 {
  24.                    
  25.                     var fioDetaile = this.fio.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  26.                     var Name = fioDetaile[0];
  27.                     var Family = fioDetaile[1];
  28.                     var SecondName = fioDetaile[2];
  29.                     return $"{Name}' '{Family}' '{SecondName}";
  30.                 }
  31.             }
  32.             private int age;
  33.             public int Age { get { return this.age; } }
  34.             public string Email { get; private set; }
  35.             public override string ToString()
  36.             {
  37.                 return $"{CapitalizeAllWords(this.fio)}\t{this.age}\t{this.Email}";
  38.             }
  39.  
  40.             public Person(string csvPerson)
  41.             {
  42.                 var personArray = csvPerson.Split(';');
  43.                 this.fio = personArray[0];
  44.                 string z = String.Join("", personArray[1].Split(',', ' '));
  45.                 this.age = Convert.ToInt32(z);
  46.                 string y = String.Join("", personArray[2].Split(' '));
  47.                 this.Email = y;
  48.             }
  49.             public string CapitalizeAllWords(string s)
  50.             {
  51.                 var sb = new StringBuilder(s.Length);
  52.                 bool inWord = false;
  53.                 foreach (var c in s)
  54.                 {
  55.                     if (char.IsLetter(c))
  56.                     {
  57.                         sb.Append(inWord ? char.ToLower(c) : char.ToUpper(c));
  58.                         inWord = true;
  59.                     }
  60.                     else
  61.                     {
  62.                         sb.Append(c);
  63.                         inWord = false;
  64.                     }
  65.                 }
  66.                 return sb.ToString();
  67.             }
  68.  
  69.             internal string Substring()
  70.             {
  71.                 throw new NotImplementedException();
  72.             }
  73.         }
  74.         static void Main(string[] args)
  75.         {
  76.             //const string text = @"Иванов иван иванович; 45;[email protected]
  77.             //    Петров Петр петрович; ,76,;
  78.             //    Сидоров Сидор Сидорович; 14; еще_не_завел@qwerty.com";
  79.  
  80.             string path = @"text.txt";
  81.  
  82.             string[] TextLines = File.ReadAllText(path, Encoding.Default).Split('\n');
  83.  
  84.            // var TextLines = text.Split('\n');
  85.            
  86.             Person[] info = new Person[TextLines.Length];
  87.             for (var i = 0; i < TextLines.Length; i++)
  88.                 info[i] = new Person(TextLines[i]);
  89.  
  90.            
  91.  
  92.             for (var i = 0; i < info.Length - 1; i++)
  93.             {
  94.                 for (var j = i + 1; j < info.Length; j++)
  95.                 {
  96.                     if (info[i].Age > info[j].Age)
  97.                     {
  98.                         var temp = info[i];
  99.                         info[i] = info[j];
  100.                         info[j] = temp;
  101.                     }
  102.                 }
  103.             }
  104.  
  105.             for (var i = 0; i < info.Length; i++)
  106.                 Console.WriteLine(info[i]);
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment