Given String str1- "happy sunday", and String str2- "sun", how can I return a string that replaces all characters in str1 with 'X' except for the occurrences of the substring s2?
So the output return value in this case should be the string - "XXXXXXsunXXX".
Note I'm not trying to print this string, but return it to a method. The method has two string parameters- str1 and str2, and has a string return value which is in this case - XXXXXXsunXXX.
This is what I have so far.. The problem is I don't know how to identify at which index str2 is occuring in str1! Once I know at which index the substring starts and ends, I can just concatenate the X signs with the substring.
public String blah(String str1, String str2)
{
int length = str1.length()-1;
String z = "";
if(!str1.contains(str2))
{
for(int i = 0; i <= length; i++)
{
z+= 'X';
}
return z;
}
else
{
...
}
}