my question is in c++.how to compare two different length string. for example string a = "ap"
string b = "apple"
. so the final match should be 1, or consider another example, let's say string a = "123"
string b = "123123123"
, the final match should be 3. so what i'm think is i try to let a[i]= b[i]
but it's just comparing only 1 charcater. how to compare a muliple length string.
int getMatchCount(string a, string b)
{
int match = 0;
if (a.length() == 0 or b.length() == 0 )
{
return -1;
}
for (int i = 0; i < a.length(); i++)
{
if( string.compare(a, b) )
{
match = match +1;
}
}
return match;
}