Advertisement
fbinnzhivko

7.00 To Uppercase

Jun 4th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Text.RegularExpressions;
  4.  
  5. class ToUppercase
  6. {
  7.     static void Main()
  8.     {
  9.         int bufSize = 32766;
  10.         Stream inStream = Console.OpenStandardInput(bufSize);
  11.         Console.SetIn(new StreamReader(inStream, Console.InputEncoding, false, bufSize));
  12.  
  13.         string text = Console.ReadLine();
  14.  
  15.         string startUpcase = "<upcase>";
  16.         string endUpcase = "</upcase>";
  17.         int countStarUpcase = Regex.Matches(Regex.Escape(text), startUpcase).Count;
  18.         int countEndcase = Regex.Matches(Regex.Escape(text), endUpcase).Count;
  19.         string result = string.Empty;
  20.  
  21.         if (countStarUpcase >= 1)
  22.         {
  23.             for (int i = 0; i < Math.Min(countStarUpcase, countEndcase); i++)
  24.             {
  25.                 int startIndex = text.IndexOf(startUpcase);
  26.                 int endIndex = text.IndexOf(endUpcase);
  27.  
  28.                 string replaceText = text.Substring(startIndex + startUpcase.Length,
  29.                     endIndex - startIndex - endUpcase.Length + 1);
  30.                 string modifiers = replaceText.ToUpper();
  31.                 result = text.Replace(replaceText, modifiers);
  32.                 result = result.Remove(startIndex, startUpcase.Length);
  33.                 result = result.Remove(startIndex + modifiers.Length, endUpcase.Length);
  34.                 text = result;
  35.             }
  36.             Console.WriteLine(result);
  37.         }
  38.         else
  39.         {
  40.             Console.WriteLine(text);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement