https://msdn.microsoft.com/zh-cn/aa315043

1、字符串提取函数,CString::Left、CString::Mid 、CString::Right

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") );

CString::Left

CString Left( int nCount ) const; throw( CMemoryException );

Return Value

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

Parameters

nCount

The number of characters to extract from this CString object.

Remarks

Extracts the first (that is, leftmost) nCount characters from this CString object and returns a copy of the extracted substring. If nCount exceeds the string length, then the entire string is extracted. Left is similar to the Basic LEFT$ 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::Left.

// example for CString::Left
CString s( _T("abcdef") );
ASSERT( s.Left(2) == _T("ab") );
CString::Right

CString::Right

CString Right( 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

nCount

The number of characters to extract from this CString object.

Remarks

Extracts the last (that is, rightmost) nCount characters from this CString object and returns a copy of the extracted substring. If nCount exceeds the string length, then the entire string is extracted. Right is similar to the Basic RIGHT$ 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::Right.

// example for CString::Right
CString s( _T("abcdef") );
ASSERT( s.Right(2) == _T("ef") );
 

转载于:https://www.cnblogs.com/fwy-walking/p/4378975.html

Cstring的使用相关推荐

  1. CString工作原理和常见问题分析

    关于Cstring 类 版权所有© Stevencao@benq.com 2003-11-6 转自:http://blog.csdn.net/laiyiling/archive/2004/10/05/ ...

  2. 对云风 cstring 第二次解析

    前言 从明天起 关心粮食和蔬菜 我有一所房子 面朝大海 春暖花开 本文前提条件 1.了解 posix 线程 2.了解 原子操作 3.具备简单C基础,或者 你也敲一遍. 如果上面不太清楚,你可以翻看我以 ...

  3. VC:CString用法整理(转载)

    1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值:否则返回0. 说明:此成员函数用来测试一个CString ...

  4. C++实现CString和string的互相转换(转)

    CString->std::string 例子: CString strMfc="test"; std::string strStl; strStl=strMfc.GetBu ...

  5. CString的用法

    1.CString::IsEmpty BOOL IsEmpty( ) const; 返回值:如果CString 对象的长度为0,则返回非零值:否则返回0. 说明:此成员函数用来测试一个CString ...

  6. BSTR 、LPCTSTR、CString附C语言串基本操作

    CString ,BSTR ,LPCTSTR之间关系和区别 CString是一个动态TCHAR数组,BSTR是一种专有格式的字符串(需要用系统提供的函数来操纵,LPCTSTR只是一个常量的TCHAR指 ...

  7. C++实现CString和string的互相转换

    2019独角兽企业重金招聘Python工程师标准>>> CString->std::string 例子: CString strMfc="test"; st ...

  8. UniCode 下 CString 转 char* 的方法

    今天进行文件操作时,将CString的GetBuffer()后直接倒到char数组后写入文件发现 每个字符与字符之间都有一个空格存在,而且有内容丢失.原来CString类对象GetBuffer(),后 ...

  9. VC++2005 CString和char*的相互转换

    原文:http://laue.cnblogs.com/archive/2005/12/26/305208.aspx 首先声明我不是一个高手,而是一个初学者,文章同样也是一个初学者对于CString和c ...

最新文章

  1. Chrome禁用浏览器跨域拦截
  2. docker-compose运行sentry
  3. 二 Array 数组常用操作方法
  4. QT的QDomElement类的使用
  5. BZOJ3508 开灯 [校内NOIP2018模拟20181027] 密码锁
  6. 开发人员必读的11本最具影响力书籍
  7. gif分解工具_Python之GIF图倒放,沙雕快乐源泉
  8. Quartz2D指定显示范围
  9. [LeetCode]题解(python):008-String to Integer (atoi)
  10. C++ Qt学习笔记(3)QT中的文本处理
  11. 开发者批评苹果商店佣金过高,库克将面临立法者质疑;花呗接入央行征信;GitHub 发布更新| 极客头条
  12. Linux的LAMP
  13. 洛谷P2939 [USACO09FEB]改造路Revamping Trails(最短路)
  14. Mongoose学习参考文档
  15. 【骚操作系列】浅谈如何将模糊的PDF清晰化
  16. 如何将离线DAT卫星影像解压为瓦片?
  17. 腾讯零反射全动态Android插件框架Shadow解析
  18. 2021年的谷歌排名优化怎么做,69个重点告诉你
  19. web数据库管理和运维软件 - webcat
  20. New type of dark energy could solve Universe expansion mystery

热门文章

  1. python cx_oracle 有超时的设置吗_python cx_Oracle的基础使用方法(连接和增删改查)
  2. python dataframe显示网格_python dataframe 输出结果整行显示的方法
  3. 加载vue文件步骤_无法在重新加载时读取vue文件
  4. android usb 触摸屏 apk,Android插入USB设备,自动弹出提示运行apk
  5. Java项目:个人博客系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)
  6. Java项目:旅游网站管理系统设计和实现(java+springboot+jsp+mysql+spring)
  7. 【蓝桥java】递归基础之反向输出字符串
  8. Express应用配置端口
  9. dva + antd + mockjs 实现用户管理
  10. matlab处理txt文件数据