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

Cstring的使用的更多相关文章

  1. CString转换为LPSTR和LPSTR转化为CString

    一.CString转换为LPSTR 方法一: CString strFileName LPSTR lpstr - strFileName.GetBuffer(); strFileName.Releas ...

  2. int与CString互相转化

    int num; CString str; //int转CString num=; str.Format(_T("%d"),num); //CString转int str=L&qu ...

  3. (转)CString截取字符串全攻略

    附:去掉空格方法 CString str("e w r we  中华ADF 华AG中"); newstr=str.Replace(" ", "&quo ...

  4. cstring to char *例子

    Cstring m_strDescPath = ""; //类的成员变量 //"打开文件"对话框,选择文件,返回其路径 m_strDescPath = Boot ...

  5. CString转换为string

    string CStringToString(CString strMFC) { CStringA strA; strA = strMFC.GetBuffer(); strMFC.ReleaseBuf ...

  6. VC++ CString类完美总结(整理)

    CString 是编程中一种非常有用的数据类型,它是MFC中的一个类,很大程度上简化了MFC中的许多字符串的操作. CString位于头文件afx.h中. ①.CString 类对象的初始化: CSt ...

  7. Unicode字符集下CString与char *转换 (解决中文乱码等)(转)

    UniCode 下 CString 转 char* 的方法的文章有很多,但是大部分都是在互相转载,看了那么多资料,仍然没有解决乱码的问题,后来从一个论坛的一条回复里面找到了正确的方法,特此拿出来与大家 ...

  8. CString std::string相互转换

    CString->std::string 例子: CString strMfc=“test“; std::string strStl; strStl=strMfc.GetBuffer(0); s ...

  9. CString转string

    如题,找了半天... //CString转string USES_CONVERSION; CString temp; temp = _T("kjdsaflkjdlfkj"); ch ...

  10. C++函数CString类常用函数

    C++ STL库里有很多与字符串操作相关的函数,熟练应用STL,字符串的处理将变得轻松.自在. 字符串截取函数: 1.CString Left( int nCount ) const;    //从左 ...

随机推荐

  1. Linux环境下安装ActiveMq

    一.准备安装的tar包 1.将安装包放在服务器上:apache-activemq-5.10.2.tar.gz 2.将安装包解压:tar -zxvf apache-activemq-5.10.2.tar ...

  2. pyinstaller-py2exe-cx_Freeze打包第一个wxPython程序HelloWorld

    pyinstaller 打包hello 7Mb ================= www.pyinstaller.org pip install pypiwin32 pip install pyin ...

  3. Mac下文件编码转换

    参见:http://bbs.feng.com/read-htm-tid-107633.html 使用: sudo find *.txt -exec sh -c "iconv -f GB180 ...

  4. HDU4965 Fast Matrix Calculation —— 矩阵乘法、快速幂

    题目链接:https://vjudge.net/problem/HDU-4965 Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Othe ...

  5. 【小程序】bindconfirm点击小键盘触发事件、focus自动获取焦点

    最近在写小程序,项目要求写一个搜索框,在进入页面时就触发input的事件,调出键盘,点小键上的搜索按钮 就触发搜索事件,分享一下. bindconfirm 是点击小键盘上的搜索按钮就触发要执行的方法 ...

  6. Java8初体验(2):Stream语法详解

    原文出处: 一冰_天锦 上篇文章Java8初体验(1):lambda表达式语法比较详细的介绍了lambda表达式的方方面面,细心的读者会发现那篇文章的例子中有很多Stream的例子.这些Stream的 ...

  7. 如何查看ffmpeg支持的编码器和封装格式

    查看支持的编码器(也就是-vcodec后面可以接的参数):ffmpeg -codecs 查看支持的封装格式(也就是-f后面可以接的参数):ffmpeg -formats 查看支持的滤镜(也就是-vf后 ...

  8. nyoj 269 VF

    VF 时间限制:1000 ms  |  内存限制:65535 KB 链接:NYOJ269 原创在:点击打开链接 题意:1-1000000000之间,各位数字之和等于给定s的数的个数. 每行给出一个数s ...

  9. PS 图像滤镜— — USM 锐化

    这个算法的原理很简单,就是先用高斯模糊获取图像的低频信息,然后用原图减去高斯模糊之后的图,得到图像的高频信息,再将原图与高频信息融合,进一步增强原图的高频信息,看起来,图像的边缘显得特别的sharp. ...

  10. CentOS环境 升级Python2.6.6至2.7.5

      1.查看当前Python版本 # python -V Python 2.6.6 # python -V Python 2.6.6 2.下载Python2.7.5源码 # wget http://p ...