Advertisement
Asenval

Untitled

Feb 1st, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. class ChangeTextBetweenTagsWithUppercase
  5. {
  6.     static void Main()
  7.     {
  8.         string str = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
  9.         Console.WriteLine("Insert string with tags <upcase>...</upcase>");
  10.         //string str = Console.ReadLine();
  11.         Regex regex = new Regex (@"(<\s*upcase\s*>)(?<tag>.*?)(<\s*/upcase\s*>)");
  12.         MatchCollection matches = regex.Matches(str);
  13.        
  14.         foreach (Match match in matches)
  15.         {
  16.             str = regex.Replace(str, match.Groups["tag"].Value.ToUpper(),1);
  17.         }
  18.         Console.WriteLine(str);
  19.     }
  20.    
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement