Advertisement
skb50bd

TagReplace

Jan 15th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. /***
  2.             Author          :   Shakib Haris
  3.             Started On      :   15 January, 2017
  4. */
  5.  
  6. using System;
  7.  
  8. class Program {
  9.     public static void Main (string[] args) {
  10.         string tag;
  11.         string rep, repCopy;
  12.         string line, lineCopy;
  13.         int end, idx;
  14.  
  15.         while ((tag = Console .ReadLine ( )) != null) {
  16.             tag = tag .ToLower ( );
  17.             rep = Console .ReadLine ( );
  18.             repCopy = rep .ToLower ( );
  19.             line = Console .ReadLine ( );
  20.             lineCopy = line .ToLower ( );
  21.  
  22.             for (int i = 0; i < line .Length; i++) {
  23.                 if (lineCopy[i] == '<') {
  24.                     end = lineCopy .IndexOf ('>', i);
  25.  
  26.                     idx = lineCopy .IndexOf (tag, i);
  27.                     while (idx != -1 && idx < end) {
  28.                         lineCopy = lineCopy .Substring (0, idx) + repCopy + lineCopy .Substring (idx + tag .Length);
  29.                         line = line .Substring (0, idx) + rep + line .Substring (idx + tag .Length);
  30.                        
  31.                         end = lineCopy .IndexOf ('>', i);
  32.                         idx = lineCopy .IndexOf (tag, i);
  33.                     }
  34.                 }
  35.             }
  36.             Console .WriteLine (line);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement