MFC的CString的find的使用
2017-02-08 23:27
274 查看
名称
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;
返回值
返回此CString对象中与需要的子字符串或字符匹配的第一个字符的从零开始的索引;如果没有找到子字符串或字符则返回-1。
参数
ch 要搜索的单个字符。
lpszSub 要搜索的子字符串。
nStart 字符串中开始搜索的字符的索引,如果是0,则是从头开始搜索。如果nStart不是0,则位于nStart之前的字符不包括在搜索之内。
pstr 指向要搜索的字符串的指针
说明
此成员函数用来在此字符串中搜索子字符串的第一个匹配的字符。函数的重载可以接收单个字符(类似于运行时函数strchr)和字符串(类似于strstr)。
示例
//下面演示第一个例子
// CString::Find( TCHAR ch )
CString s( "abcdef" );
int n = s.Find( 'c' ); // 结果 n = 2
int f = s.Find( "de" ) ; // 结果 f = 3
ASSERT( n == 2 );
ASSERT( f == 3 );
// 下面演示第二个例子
// CString::Find(TCHAR ch,int nStart)
CString str("The stars are aligned");
int n = str.Find('e',5); //结果 n = 12
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;
返回值
返回此CString对象中与需要的子字符串或字符匹配的第一个字符的从零开始的索引;如果没有找到子字符串或字符则返回-1。
参数
ch 要搜索的单个字符。
lpszSub 要搜索的子字符串。
nStart 字符串中开始搜索的字符的索引,如果是0,则是从头开始搜索。如果nStart不是0,则位于nStart之前的字符不包括在搜索之内。
pstr 指向要搜索的字符串的指针
说明
此成员函数用来在此字符串中搜索子字符串的第一个匹配的字符。函数的重载可以接收单个字符(类似于运行时函数strchr)和字符串(类似于strstr)。
示例
//下面演示第一个例子
// CString::Find( TCHAR ch )
CString s( "abcdef" );
int n = s.Find( 'c' ); // 结果 n = 2
int f = s.Find( "de" ) ; // 结果 f = 3
ASSERT( n == 2 );
ASSERT( f == 3 );
// 下面演示第二个例子
// CString::Find(TCHAR ch,int nStart)
CString str("The stars are aligned");
int n = str.Find('e',5); //结果 n = 12
相关文章推荐
- VC程序在非MFC中使用CString
- 非MFC中使用Cstring
- 【MFC】将CString类型的十六进制数字,转换成整形(在使用Unicode字符集的情况)
- MFC的CString使用
- 在非MFC项目中使用CString
- 使用C++编写类似MFC的CString,部分功能,重新复习使用操作符重载
- Cmap和Carray以及Cstring的使用以及MFC中的文件读写
- VS2012 MFC中CString的Format方法使用
- 非MFC项目使用CString及如何打印
- MFC 常用类 Cstring 方法使用:
- 如何在Console程序中使用MFC类(例如CString)
- MFC CString 查找函数使用的三个失误
- MFC AtlMap<CString, ?>使用
- 在使用MFC双向链表模板类CList中Find问题
- MFC获取应用程序所在目录--CString(Left、Right、Find、ReverseFind)--Cstring与char或wchar转换
- 非MFC工程使用CString
- VC程序在非MFC中使用CString
- MFC中CString的Format方法使用技巧
- 在非MFC中使用CString
- MFC中CString的Format方法使用技巧