c++ MFC中怎样获取部分字符串,定义CSring s=“adbdksf”比如获取第二个到第四个字符

 我来答
百度网友a9ca369
2011-03-07 · TA获得超过143个赞
知道小有建树答主
回答量:200
采纳率:0%
帮助的人:167万
展开全部
MSDN 上的介绍
CString 有下面几个函数
Mid Extracts the middle part of a string (like the Basic MID$ function).
Left Extracts the left part of a string (like the Basic LEFT$ function).
Right Extracts the right part of a string (like the Basic RIGHT$ function).
SpanIncluding Extracts a substring that contains only the characters in a set.
SpanExcluding Extracts a substring that contains only the characters not in a set.
点 Mid

CString::Mid
CString Mid( int nFirst ) const;
throw( CMemoryException );

CString Mid( int nFirst, int nCount ) const;
throw( CMemoryException );

Return Value

A CString object that contains a copy of the specified range of characters. Note that the returned CString object may be empty.

Parameters

nFirst

The zero-based index of the first character in this CString object that is to be included in the extracted substring.

nCount

The number of characters to extract from this CString object. If this parameter is not supplied, then the remainder of the string is extracted.

Remarks

Extracts a substring of length nCount characters from this CString object, starting at position nFirst (zero-based). The function returns a copy of the extracted substring. Mid is similar to the Basic MID$ function (except that indexes are zero-based).

For multibyte character sets (MBCS), nCount refers to each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two characters.

Example

The following example demonstrates the use of CString::Mid.

// example for CString::Mid
CString s( _T("abcdef") );
ASSERT( s.Mid( 2, 3 ) == _T("cde") );
第2到第4(序号是从0开始的 indexes are zero-based,第2个就是1,2到4总共3个字符)

s,Mid(1,3)
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
chthoa_456
2011-03-07 · 超过15用户采纳过TA的回答
知道答主
回答量:19
采纳率:0%
帮助的人:0
展开全部
用CString的Mid函数,第一个参数是从第几个开始,第二个参数是取多少个,返回值是一个新的CString对象。
如CString str = "123456";
CString substr = str.Mid(2,2);
返回“34“
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
军军106
2011-03-07 · TA获得超过453个赞
知道小有建树答主
回答量:1747
采纳率:0%
帮助的人:765万
展开全部
直接取啊,如:s[1]、s[3]
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友96aa8d3
2011-03-07 · TA获得超过433个赞
知道小有建树答主
回答量:2306
采纳率:75%
帮助的人:950万
展开全部
cstring c;
c.assign(s,2,4);
头文件#include<string.h>

建议看下c++模板
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式