请问C++的字符串find()函数的用法?

如果我明白了,再追加分... 如果我明白了,再追加分 展开
 我来答
zh186
2008-09-25
知道答主
回答量:2
采纳率:0%
帮助的人:0
展开全部
CString::Find
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;

Return Value
The zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found.
这是我从MSDN上COPY下来的
意思是说从第nStart个字符开始查找字符ch或字符串pstr。
找到的话返回值是ch在CString这个字符串中的位置
找不到的话返回值-1
zero-based index就是说字符串的第一个字符串对应的nstart是0
比如说
CString test="asdfjkll";
test.find('c')的值是-1
test.find('d')的值是2
…………
百度网友98c8a11
推荐于2016-07-09 · TA获得超过1172个赞
知道小有建树答主
回答量:261
采纳率:0%
帮助的人:441万
展开全部
不是很难的东西,不用翻译了吧,From MSDN:
CString::Find
int Find( TCHAR ch ) const;

int Find( LPCTSTR lpszSub ) const;

int Find( TCHAR ch, int nStart ) const;

int Find( LPCTSTR pstr, int nStart ) const;

Return Value

The zero-based index of the first character in this CString object that matches the requested substring or characters; -1 if the substring or character is not found.

Parameters

ch

A single character to search for.

lpszSub

A substring to search for.

nStart

The index of the character in the string to begin the search with, or 0 to start from the beginning. The character at nStart is excluded from the search if nStart is not equal to 0.

pstr

A pointer to a string to search for.

Remarks

Searches this string for the first match of a substring. The function is overloaded to accept both single characters (similar to the run-time function strchr) and strings (similar to strstr).

Example

// First example demonstrating
// CString::Find ( TCHAR ch )
CString s( "abcdef" );
ASSERT( s.Find( 'c' ) == 2 );
ASSERT( s.Find( "de" ) == 3 );

// Second example demonstrating
// CString::Find( TCHAR ch, int nStart )
CString str("The stars are aligned");
int n = str.Find('e', 5);
ASSERT(n == 12);
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式