温馨提示×

CString::ReverseFind()和CString::Find()区别

小亿
87
2023-12-20 14:28:07
栏目: 编程语言

CString::ReverseFind()是CString类的成员函数,用于在字符串中从后往前查找指定字符或子串,并返回第一次出现的位置。该函数的原型如下:

int ReverseFind( TCHAR ch ) const;
int ReverseFind( TCHAR ch, int nStart ) const;
int ReverseFind( LPCTSTR lpszSub ) const;
int ReverseFind( LPCTSTR lpszSub, int nStart ) const;

其中,参数ch表示要查找的字符,参数nStart表示从哪个位置开始查找,默认为字符串的末尾,参数lpszSub表示要查找的子串。

CString::Find()也是CString类的成员函数,用于在字符串中从前往后查找指定字符或子串,并返回第一次出现的位置。该函数的原型如下:

int Find( TCHAR ch ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( LPCTSTR lpszSub, int nStart ) const;

与ReverseFind()函数相比,Find()函数的作用相反,它是从前往后查找字符串,而不是从后往前查找。其余参数的含义与ReverseFind()函数相同。

总结来说,CString::ReverseFind()函数是从后往前查找指定字符或子串,而CString::Find()函数是从前往后查找。

0