Advertisement
braveheart1989

ToUppercase

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