Advertisement
petromaxa

Untitled

Jan 31st, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _5.ChangeTextInTheTags
  7. {
  8. class ChangeTextInTheTags
  9. {
  10. static void Main()
  11. {
  12. string str = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";
  13. string searchedPattern = "</";
  14. string newString = str.Replace(searchedPattern, "");
  15. int numberOfTags = (str.Length - newString.Length) / searchedPattern.Length;
  16. int startSearchIndex = 0;
  17. for (int i = 0; i < numberOfTags; i++)
  18. {
  19. int startTagEndIndex = str.IndexOf(">",startSearchIndex);
  20. int endTagStartIndex = str.IndexOf("</", startTagEndIndex);
  21. string betweenTags = str.Substring(startTagEndIndex + 1, endTagStartIndex - startTagEndIndex - 1);
  22. str = str.Remove(startTagEndIndex + 1,endTagStartIndex - startTagEndIndex - 1);
  23. str = str.Insert(startTagEndIndex+1,betweenTags.ToUpper());
  24. int endTagEndIndex = str.IndexOf(">", endTagStartIndex);
  25. startSearchIndex = endTagEndIndex + 1;
  26. }
  27. Console.WriteLine(str);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement