我需要在其他字符串中找到最长的字符串,所以如果string1是“Alibaba”,string2是“ba”,最长的字符串将是“baba”。我有长度的字符串,但接下来呢?如何在字符串中找到字符串
char* fun(char* a, char& b)
{
int length1=0;
int length2=0;
int longer;
int shorter;
char end='\0';
while(a[i] != tmp)
{
i++;
length1++;
}
int i=0;
while(b[i] != tmp)
{
i++;
length++;
}
if(dlug1 > dlug2){
longer = length1;
shorter = length2;
}
else{
longer = length2;
shorter = length1;
}
//logics here
}
int main()
{
char name1[] = "Alibaba";
char name2[] = "ba";
char &oname = *name2;
cout << fun(name1, oname) << endl;
system("PAUSE");
return 0;
}
如果你想要实现这个使用正则表达式,你可以看看http://www.boost.org/doc/libs/ 1_42_0/libs/regex/doc/html/index.html – ereOn 2010-03-29 13:26:34