MuffinMonster

Class Task 55#

Mar 10th, 2014
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static string Replace(string text, string st1, string st2)
  11.         {
  12.             int x, y;
  13.             x = text.IndexOf(st1);
  14.             y = text.IndexOf(st2);
  15.             if (x > y)
  16.             {
  17.                 text = text.Replace(st2, st1);
  18.             }
  19.             else
  20.                 text = text.Replace(st1, st2);
  21.             return text;
  22.         }
  23.         static void Main(string[] args)
  24.         {
  25.             string text = Console.ReadLine();
  26.             string word = Console.ReadLine();
  27.             string word2 = Console.ReadLine();
  28.             Console.WriteLine(Replace(text, word, word2));
  29.             Console.ReadLine();
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment