Question
Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Question Submitted By :: Kunal
I also faced this Question!!
Rank
Answer Posted By
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 1
int countX=0;
int countY=0;
string tmp=x;
for(countX=1;countX<=x.lenth();countX++)
{
for(countY=1;countY<=y.length();countY++)
{
if x.substring(1,countX).Equels(y.substring(1,countY)
{
tmp=tmp.Replace(tmp.substring(1,countX),"");
}
}
}
x=tmp;
Sourabh Bose
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 2
'e'and 'o'
Gopichandar
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 3
x="hello", y="open"
so we have to remove e and o from x, so its hll
Shilpa
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 4
class Stringb
{
public static void main(String a[])
{
StringBuffer sb=new StringBuffer("Hello");
StringBuffer sb1=sb.deleteCharAt(1);
StringBuffer sb2=sb1.deleteCharAt(3);
System.out.println(sb2);
}
}
Nisha Sharma
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 5
public static void main(String[] args) {
String str_x = "hello";
String str_y = "open";
StringBuffer result = new StringBuffer();
for (int i=0; i<str_x.length();i++){
if (str_y.indexOf(str_x.charAt(i)) < 0)
result.append(str_x.charAt(i));
}
System.out.print(result);
}
Guest
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 6
Public abstract ClassDemo
{
public static void main(string args[]){
StringBuffer sb1= new stringBuffer("Hello");
StringBuffer sb2= new stringBuffer("open");
stringbuffer a= sb.deletecharacterAt("hello",1);
system.out.println("the value of a:"+a);
stringBuffer x=sb.deletecharacterAt("hllo"3);
system.out.println(x:+"x");
}
Bijoy Kumar Baral
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 7
static public string StupidQuestion(string x, string y)
{
StringBuilder sb = new StringBuilder();
Hashtable ht = new Hashtable();
// just one pass through y
foreach( char c in y.ToCharArray() )
if( !ht.Contains(c) )
ht.Add(c, c)
// just one pass thru x
foreach( char c in x.ToCharArray() )
if( !ht.Contains(c) )
sb.Append(c);
return sb.ToString();
}
Skybeaver
Re: Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.
Answer
# 8
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string str = "mohim";
string str1 = "mo";
remove(str, str1);
}
private static void remove(string str,string str1)
{
char[] abc;
abc = str.ToCharArray();
char[] bcd;
string str4 = "";
bcd = str1.ToCharArray();
for (int i = 0; i < bcd.Length; i++)
{
for (int j = 0; j < abc.Length; j++)
{
if (abc[j] != bcd[i])
{
str4 = str4 + abc[j];
}
}
abc = str4.ToCharArray();
str4 = "";
}
Console.Write(abc);
Console.ReadLine();
}
}
}
Jethvamohit