JulianJulianov

05.TextProcessingLab-Digits, Letters and Other

Apr 16th, 2020
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. 05. Digits, Letters and Other
  2. Write a program that receives a single string and on the first line prints all the digits, on the second – all the letters, and on the third – all the other characters. There will always be at least one digit, one letter and one other characters.
  3. Examples
  4. Input                 Output
  5. Agd#53Dfg^&4F53       53453
  6.                       AgdDfgF
  7.                       #^&
  8. Hints
  9. • Read the input.
  10. • Use loop to iterate through all characters in the text. If the char is digit print it, otherwise ignore it.
  11. o   Use char.IsDigit(char symbol)
  12. Do the same for the letters and other chars
  13. o   Find something like IsDigit method for the letters.
  14.  
  15. using System;
  16. using System.Collections.Generic;
  17.  
  18. namespace ExamResults
  19. {
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.              var anySymbols = Console.ReadLine();
  25.             var allDigits = "";
  26.             var allLetters = "";
  27.             var allOthers = "";
  28.             foreach (var item in anySymbols)
  29.             {
  30.                 if (Char.IsLetterOrDigit(item))
  31.                 {
  32.                     if (Char.IsDigit(item))
  33.                     {
  34.                         allDigits += item;
  35.                     }
  36.                     else
  37.                     {
  38.                         allLetters += item;
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     allOthers += item;
  44.                 }
  45.             }
  46.             var result = new List<string>();
  47.             result.Add(allDigits);
  48.             result.Add(allLetters);
  49.             result.Add(allOthers);
  50.             Console.WriteLine(string.Join("\n", result));
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment