Advertisement
Assi

13. Strings and Text Processing 5. ToUpperTextBetweenTags

Jan 24th, 2013
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. class ToUpperTextBetweenTags
  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.         int startIndex = 0;
  10.         int endIndex = 0;
  11.         Console.WriteLine(str);
  12.        
  13.         for (int i = 0; i < str.Length - 8; i++)
  14.         {
  15.             if (str.Substring(i, 8) == "<upcase>")
  16.             {
  17.                 startIndex = i + 8;
  18.                 i = startIndex;
  19.             }
  20.             if (str.Substring(i, 9) == "</upcase>")
  21.             {
  22.                 endIndex = i;
  23.                 int length = endIndex - startIndex;
  24.                 string upperStr = str.Substring(startIndex, length).ToUpper();
  25.                 //Console.WriteLine(upperStr);
  26.                 str = str.Remove(startIndex, length);
  27.                 //Console.WriteLine(str);
  28.                 str = str.Insert(startIndex, upperStr);
  29.                 //Console.WriteLine(str);
  30.                 str = str.Remove(startIndex - 8, 8);
  31.                 str = str.Remove(endIndex-8, 9);
  32.             }
  33.         }
  34.         Console.WriteLine(str);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement