Advertisement
vandeva

Extract Person Information

Jul 18th, 2019
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Extract_Person_Info_2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int lines = int.Parse(Console.ReadLine());
  10.  
  11.             for (int i = 0; i < lines; i++)
  12.             {
  13.                 string[] text = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
  14.  
  15.                 string name = string.Empty;
  16.                 string age = string.Empty;
  17.  
  18.                 foreach (var word in text)
  19.                 {
  20.                     if (word.StartsWith('@'))
  21.                     {
  22.                         name = word.Substring(1, word.Length - 2);
  23.                     }
  24.                     else if (word.StartsWith('#'))
  25.                     {
  26.                         age = word.Substring(1, word.Length - 2);
  27.                     }
  28.  
  29.                 }
  30.                 Console.WriteLine($"{name} is {age} years old.");
  31.             }
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement