Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace LettersToUpper
  8. {
  9.     class LettersToUpper
  10.     {
  11.         static string ToUpper(string text)
  12.         {
  13.             string pattern = @"(?'OpenTag'<upcase>)(?'TagContent'.*?)(?'CloseTag'</upcase>)";
  14.             StringBuilder resultString = new StringBuilder(text.Length, text.Length);
  15.             int LastIndex = 0;
  16.  
  17.             Regex regex = new Regex(pattern);
  18.  
  19.             Match match = regex.Match(text);
  20.  
  21.             while (match.Success)
  22.             {
  23.                 string patch = text.Substring(LastIndex, match.Index - LastIndex);
  24.                 string upperCasePatch = match.Groups["TagContent"].ToString();
  25.  
  26.                 resultString.Append(patch);
  27.                 resultString.Append(upperCasePatch.ToUpper());
  28.  
  29.                 LastIndex = match.Index + match.Length;
  30.                 match = match.NextMatch();
  31.             }
  32.  
  33.             resultString.Append(text.Substring(LastIndex));
  34.  
  35.             return resultString.ToString();
  36.         }
  37.  
  38.         static void Main(string[] args)
  39.         {
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement