首页 > 编程语言 > 详细

std::string与MFC的CString的比较

时间:2019-07-20 09:12:44      阅读:287      评论:0      收藏:0      [点我收藏+]

关于CString的详细用法,参见:www.cnblogs.com/htj10/p/9341545.html

关于std::string的详细用法,参见:http://www.cplusplus.com/reference/string/string/?kw=string

1. 查找字符(串)-- 完全匹配,返回首次出现位置
CString:
int Find( TCHAR ch ) const;
int Find( LPCTSTR lpszSub ) const;
int Find( TCHAR ch, int nStart ) const;
int Find( LPCTSTR pstr, int nStart ) const;
查找字串,nStart为开始查找的位置。未找到匹配时返回-1,否则返回字串的开始位置
std::string:

string (1)
size_t find (const string& str, size_t pos = 0) const;
c-string (2)
size_t find (const char* s, size_t pos = 0) const;
buffer (3)
size_t find (const char* s, size_t pos, size_t n) const;
character (4)
size_t find (char c, size_t pos = 0) const;

2. 查找字符串 -- 匹配字符串中某一个字符就行,返回首次出现位置
CString:
int FindOneOf( LPCTSTR lpszCharSet ) const;
查找lpszCharSet中任意一个字符在CString对象中的匹配位置。未找到时返回-1,否则返回字串的开始位置

std::string:

 

string (1)
size_t find_first_of (const string& str, size_t pos = 0) const;
c-string (2)
size_t find_first_of (const char* s, size_t pos = 0) const;
buffer (3)
size_t find_first_of (const char* s, size_t pos, size_t n) const;
character (4)
size_t find_first_of (char c, size_t pos = 0) const;

 

When pos is specified, the search only includes characters at or after position pos, ignoring any possible occurrences before pos.

3. 获取字符串的一部分
CString:
CString Left( int nCount ) const;    从左边取nCount个字符
CString Right( int nCount ) const;  从右边取nCount个字符
CString Mid( int nFirst ) const;       从nFirst位置到结尾 [nFirst, -1)
CString Mid( int nFirst, int nCount ) const;  从nFirst位置后nCount个字符 [nFirst, nFirst+nCount)

std::string:
string substr (size_t pos = 0, size_t len = npos) const;    从pos位置开始后len个字符,[pos,pos+len)  ,若没指定len则到字符串结尾 即 [pos,npos) 
The substring is the portion of the object that starts at character position pos and spans len characters (or until the end of the string, whichever comes first).

 

std::string与MFC的CString的比较

原文:https://www.cnblogs.com/htj10/p/11216277.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!