忽略CString的一部分 [英] Ignoring a part of a CString

查看:107
本文介绍了忽略CString的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我无法忽略MFC C ++应用程序中字符串的一部分.这是我的示例:

Hi, my problem is i can''t ignore a part of a string in MFC C++ application. Here is my example:

<br />
CString name = "George says something";<br />



我的观点是,我需要获取字符串中的名称,而不是仅获取名称,我想忽略说些什么"部分. 乔治"包含6个符号并且很容易获得,但是如果我使用迈克尔"之类的其他名称,则它有7个符号.所以我只需要得到名字.我该怎么做?



My point is that i need to get the name in the string but instead of getting the the name only, i want to ignore the part "says something". "George" contains 6 symbols and would be easy to get it, but if i use another name like "Michael", it has 7 symbols. So i need to get the name only. How can i do it? Thanks in advance!

推荐答案

尝试使用CString :: FindOneOf方法查找空间,然后提取所需的字符串部分.
MSDN文档
Try using the CString::FindOneOf method to find the space and then pull the portion of the string you want.
MSDN documentation


如果您始终想获取第一个单词",则可以将所有内容解析到第一个空格",但是要在字符串中任何地方搜索看起来像名称的单词将是一个挑战.
If you always want to get the first "word" you can parse everything up to the first "space", but to search for a word that looks like a name anywhere in the string is going to be a challenge.


您可以使用 CString :: Tokenize [ ^ ]方法,例如:
You may use the CString::Tokenize[^] method, for instance:
CString sentence = "George says something";
int start_pos = 0;
CString name = sentence.Tokenize(" ", start_pos);


:)


这篇关于忽略CString的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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