Advertisement
wnvko

C# Part2 VIII. Strings and Text Processing - 5

Jan 6th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. namespace CaseSwitcher
  2. {
  3.     using System;
  4.     using System.Text.RegularExpressions;
  5.  
  6.     public class CaseSwitcher
  7.     {
  8.         public static string TakeUserInput(string adviseString)
  9.         {
  10.             Console.WriteLine(adviseString);
  11.             string userExpression = Console.ReadLine();
  12.             return userExpression;
  13.         }
  14.  
  15.         public static void Main(string[] args)
  16.         {
  17.             string userString = TakeUserInput("Enter a string with necessary tags: ");
  18.             string changedString = Regex.Replace(
  19.                                                  userString,
  20.                                                  @"(?<=<upcase>)(.+?)(?=</upcase>)",
  21.                                                  delegate(Match match)
  22.                                                  {
  23.                                                      string text = match.ToString();
  24.                                                      return text.ToUpper();
  25.                                                  });
  26.  
  27.             changedString = Regex.Replace(changedString, @"<.+?>", string.Empty);
  28.             Console.WriteLine();
  29.             Console.WriteLine(changedString);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement