Given two strings, str1 and str2 as input, remove all chars from str1 that appear in str2.
MYApproach
In my function I took 2 Strings.In for loop I am checking each character position whether that character in string1 matches in string2.If it does not match I increment a count.If it matches I do not increment.I also checked whether count is qual to my length of second string.If it does,I then added String1 character to a new String
Below is my Updated Code for today:
public String remove(String str1, String str2)
{
String strnew="";
int count=0;
int p=0;
//int j=0;
int l1=str1.length();
int l2=str2.length();
for(int j=0;j<l1;)
{
char ch1=str1.charAt(p);
char ch2=str2.charAt(j);
if(ch1!=ch2)
{
count++;
j++;
if(count==l1)
{
strnew=strnew+ch1;
p++;
j=0;
count=0;
}
}
else
{
p++;
count=0;
j=0;
}
}
return strnew;
//write your code here
}
}
I am getting the following error:
Output TestcaseParameters Testcase Actual Answer Expected
No output 'Hello''World' null He
Can anyone tell me why I am getting this error?
Thank you in advance.