使用 MFC CString 的 boost 字符串算法来检查字符串的结尾
我需要检查 MFC
中的 CString
对象是否以特定字符串结尾。
我知道 boost::algorithm 有许多用于字符串操作的函数,并且在 header boost/algorithm/string/predicate.hpp 中可以将其用于此目的。
我通常将此库与 std::string
一起使用。您知道与 CString
一起使用该库的便捷方法吗?
我知道该库是通用的,也可以与用作模板参数的其他字符串库一起使用,但尚不清楚(以及是否可能)将此功能应用于 CString。
如果可能的话,你能帮我吗?
I need to check whether my CString
object in MFC
ends with a specific string.
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.
I usually use this library with std::string
. Do you know a convenient way to use this library also with 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Boost 字符串算法库,“查阅设计章节查看支持的精确规范字符串类型”,除其他外,“字符串类型的首要要求是它必须可以使用 Boost.Range",并注意底部的 MFC/ATL 由 Shunsuke Sogame 编写,它应该允许您组合库。
编辑:由于您在下面的评论中提到了正则表达式,这就是您真正需要做的所有事情(假设是 unicode 构建):
请注意我们如何将不同的字符串类型简化为原始指针以在库之间传递它们。将我设计的
yourRegex
替换为您的要求,包括您是否忽略大小写或是否明确锚点。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.
Edit: Since you mention regex in the comments below, this is all you really need to do (assuming a unicode build):
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.为什么不给自己省点麻烦,直接使用 CStringT::Right?
Why don't you save yourself the trouble and just use CStringT::Right?