Two strings are given, remove all occurrences or the characters in the second string from the first string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace RemoveRepeatedCharacters
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the orirginal string");
string str = Console.ReadLine();
Console.WriteLine("Enter the characters to be removed string");
string rem = Console.ReadLine();
Hashtable remhash = new Hashtable();
foreach (char ch in rem)
{
if (!remhash.ContainsValue(ch))
{
remhash.Add((int)ch, ch);
}
}
string final = "";
foreach (char ch in str)
{
if (!remhash.ContainsValue(ch))
{
final = final + ch;
}
}
Console.WriteLine(final);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace RemoveRepeatedCharacters
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the orirginal string");
string str = Console.ReadLine();
Console.WriteLine("Enter the characters to be removed string");
string rem = Console.ReadLine();
Hashtable remhash = new Hashtable();
foreach (char ch in rem)
{
if (!remhash.ContainsValue(ch))
{
remhash.Add((int)ch, ch);
}
}
string final = "";
foreach (char ch in str)
{
if (!remhash.ContainsValue(ch))
{
final = final + ch;
}
}
Console.WriteLine(final);
Console.ReadLine();
}
}
}
Comments
Post a Comment