HOW TO FIND DIFFERENCES BETWEEN TWO STRINGS ?
Open console Application
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public void testmethod(string str1, string
str2)
{
string Op1 = str1;
string Op2 = str2;
foreach (char character
in str2.ToCharArray())
{
Op1
= Op1.Replace(character.ToString(), "");
}
foreach (char character
in str1.ToCharArray())
{
Op2
= Op2.Replace(character.ToString(), "");
}
Console.WriteLine("all Characters which is present in str1 and not in
str2:{0}", Op1);
Console.WriteLine("all Characters which is present in str2 and not in
str1:{0}", Op2);
}
static void Main(string[]
args)
{
string str1 = Convert.ToString(Console.ReadLine());
string str2 = Convert.ToString(Console.ReadLine());
Program p = new Program();
p.testmethod(str1,str2);
Console.ReadLine();
}
}
}
OUTPUT:
DESCRIPTION:
In op1(First operation str1-str2 is happening like …VAMSI-IA=VMS)…
VAMSI:VMS// ” I” and “A” IN SECOND STRING
In op2 (Second operation str2-str1 is happening like… INDLA-IA=NDL)
INDLA:NDL// ” I” and “A” IN FIRST STRING
No comments:
Post a Comment