使用boost字符串变换算法使用MFC的CString来检查字符串的结尾 [英] using boost string algorithm with MFC CString to check for the end of a string

查看:141
本文介绍了使用boost字符串变换算法使用MFC的CString来检查字符串的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查 MFC 我的的CString 对象是否具有特定字符串结尾。

I need to check whether my CString object in MFC ends with a specific string.

我知道的boost ::算法具有很多功能意味着字符串操作,并且在头升压/算法/串/ predicate.hpp 是否可用于这一目的。

I know that boost::algorithm has many functions meant for string manipulation and that in the header boost/algorithm/string/predicate.hpp could it be used for that purpose.

我通常使用这个库的std ::字符串。你知不知道也使用这个库的CString 一个方便的方法?

I usually use this library with std::string. Do you know a convenient way to use this library also with CString?

我知道库是也可与用作模板参数其他字符串库可使用通用的,但它是不明确(以及是否是可能的)这个功能适用于 CString的

I know that the library is generic that can be used also with other string libraries used as template arguments, but it is not clear (and whether is possible) to apply this feature to CString.

您能帮我,在情况下,有可能吗?

Can you help me with that in case it is possible?

推荐答案

据的升压字符串算法库,咨询的设计章看到支持的字符串类型的precise规范,这表示除其他事项外,字符串类型的第一个要求是它必须[是]访问使用的 Boost.Range ,并注意底部的<一个HREF =htt​​p://www.boost.org/doc/libs/1_43_0/libs/range/doc/html/range/mfc_atl.html相对=nofollow> MFC / ATL 通过书面俊介实施Sogame它应该让你组合库。

According to Boost String Algorithms Library, "consult the design chapter to see precise specification of supported string types", which says amongst other things, "first requirement of string-type is that it must [be] accessible using Boost.Range", and note at the bottom the MFC/ATL implementation written by Shunsuke Sogame which should allow you to combine libraries.

编辑:既然你提到在下面的评论正则表达式,这是你真正需要做的(假设一单code版本):

Since you mention regex in the comments below, this is all you really need to do (assuming a unicode build):

CString inputString;
wcmatch matchGroups;
wregex yourRegex(L"^(.*)$"), regex::icase);
if (regex_search(static_cast<LPCWSTR>(inputString), matchGroups, yourRegex))
{
    CString firstCapture = matchGroups[1].str().c_str();
}

请注意,我们如何减少不同的字符串类型原始指针库之间传递它们。取代我做作 yourRegex ​​符合您的要求,包括是否不能忽略的情况下或有明确的关于锚。

Note how we reduce the different string types to raw pointers to pass them between libraries. Replace my contrived yourRegex with your requirements, including whether or not you ignore case or are explicit about anchors.

这篇关于使用boost字符串变换算法使用MFC的CString来检查字符串的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆