Advertisement
elena1234

ExtractPersonInformation

Nov 15th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace ExtractPersonInformation
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             int numberOfLines = int.Parse(Console.ReadLine());
  11.  
  12.             for (int i = 0; i < numberOfLines; i++)
  13.             {
  14.                 string text = Console.ReadLine();
  15.                 int startIndexName = text.IndexOf('@')+1;
  16.                 int endIndexName = text.IndexOf('|');
  17.                 int nameLength = endIndexName - startIndexName;
  18.                 string name = text.Substring(startIndexName, nameLength);
  19.  
  20.                 int startIndexAge = text.IndexOf('#')+1;
  21.                 int endIndexAge = text.IndexOf('*');
  22.                 int ageLength = endIndexAge - startIndexAge;
  23.                 string age = text.Substring(startIndexAge, ageLength);
  24.                 Console.WriteLine($"{name} is {age} years old.");
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement