Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text.RegularExpressions;
- class ToUppercase
- {
- static void Main()
- {
- int bufSize = 32766;
- Stream inStream = Console.OpenStandardInput(bufSize);
- Console.SetIn(new StreamReader(inStream, Console.InputEncoding, false, bufSize));
- string text = Console.ReadLine();
- string startUpcase = "<upcase>";
- string endUpcase = "</upcase>";
- int countStarUpcase = Regex.Matches(Regex.Escape(text), startUpcase).Count;
- int countEndcase = Regex.Matches(Regex.Escape(text), endUpcase).Count;
- string result = string.Empty;
- if (countStarUpcase >= 1)
- {
- for (int i = 0; i < Math.Min(countStarUpcase, countEndcase); i++)
- {
- int startIndex = text.IndexOf(startUpcase);
- int endIndex = text.IndexOf(endUpcase);
- string replaceText = text.Substring(startIndex + startUpcase.Length,
- endIndex - startIndex - endUpcase.Length + 1);
- string modifiers = replaceText.ToUpper();
- result = text.Replace(replaceText, modifiers);
- result = result.Remove(startIndex, startUpcase.Length);
- result = result.Remove(startIndex + modifiers.Length, endUpcase.Length);
- text = result;
- }
- Console.WriteLine(result);
- }
- else
- {
- Console.WriteLine(text);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement