Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _5.ChangeTextInTheTags
- {
- class ChangeTextInTheTags
- {
- static void Main()
- {
- string str = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
- string searchedPattern = "</";
- string newString = str.Replace(searchedPattern, "");
- int numberOfTags = (str.Length - newString.Length) / searchedPattern.Length;
- int startSearchIndex = 0;
- for (int i = 0; i < numberOfTags; i++)
- {
- int startTagEndIndex = str.IndexOf(">",startSearchIndex);
- int endTagStartIndex = str.IndexOf("</", startTagEndIndex);
- string betweenTags = str.Substring(startTagEndIndex + 1, endTagStartIndex - startTagEndIndex - 1);
- str = str.Remove(startTagEndIndex + 1,endTagStartIndex - startTagEndIndex - 1);
- str = str.Insert(startTagEndIndex+1,betweenTags.ToUpper());
- int endTagEndIndex = str.IndexOf(">", endTagStartIndex);
- startSearchIndex = endTagEndIndex + 1;
- }
- Console.WriteLine(str);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement