Hi All,
I have written the below program to find the substring in the string. in case one word coming multiple time how to handle this situation ? the below program retuning -1 as position which is wrong.
Code
Input ("abhijit" , "jit")
public int FindSubString(string strSuper, string strSub)
{
char[] charSuper = strSuper.ToCharArray();
char[] charSub = strSub.ToCharArray();
//int position = -1;
for (int i = 0; i <= charSuper.Length - charSub.Length; i++)
{
int counter = 0;
for (int J = 0; J < charSub.Length; J++)
{
if (charSuper[i] != charSub[J])
continue;
else
{
i++;
counter++;
}
}
if (counter == charSub.Length)
position = i - charSub.Length;
}
return position;
}
Copyright GeekInterview.com
How to fixi it ?
Find subString in String
I have written the below program to find the substring in the string. in case one word coming multiple time how to handle this situation ? the below program retuning -1 as position which is wrong.
How to fixi it ?
Questions by yrs_abhishek
Related Answered Questions
Related Open Questions