zoukankan      html  css  js  c++  java
  • [转载]CString类常用方法----Left(),Mid(),Right()……

    CStringLeft(intnCount)const; //从左边1开始获取前 nCount个字符  

    CStringMid(intnFirst)const; //从左边第 nCount+1个字符开始,获取后面所有的字符  

    CStringMid(intnFirst,intnCount)const; //从左边第 nFirst+1 个字符开始,获取后面nCount个字符  

    CStringRight(intnCount)const; //从右边1开始获取从右向左前 nCount个字符  

    voidMakeUpper(); //这个函数可以将CString字符转化为一个大写的字符串。  

    注:  

    在函数后面加 const 的意思是:  

    如果一个类声明了一个常量对象,这个对象只能使用后边带 const 这个的方法.  

    例:  

    CString a,b;

     a = "123456789";  

    b =a.eft(4);  //值为:1234  

    b =a.Mid(3); //值为:456789  

    b = a.Mid(2, 4); //值为:3456  

    b = a.Right(4);  //值为:6789  

    The following example demonstrates the useof CString::MakeUpper.  

     

    //example for CString::MakeUpper CStrings( "abc" ); s.MakeUpper(); ASSERT(s == "ABC" );  

    在一个较大的字符串中查找字符或子字符串  

    int Find( TCHAR ch ) const;  

    int Find( LPCTSTR lpszSub ) const;  

    intFind( TCHAR ch, int nStart ) const;intFind( LPCTSTR pstr, int nStart ) const;  

    返回值  

    返回此CString对象中与需要的子字符串或字符匹配的第一个字符的从零开始的索引;如果没有找到子字符串或字符则返回-1。  

    参数  

    ch要搜索的单个字符。 lpszSub要搜索的子字符串。 nStart字符串中开始搜索的字符的索引,如果是0,则是从头开始搜索。如果nStart不是0,则位于nStart之前的字符不包括在搜索之内。 pstr指向要搜索的字符串的指针  

    / CString::Find( TCHAR ch )  

    CStrings( "abcdef" ); intn = s.Find( 'c' ); // 结果 n = intf = s.Find( "de" ) ; // 结果 f = 3  

  • 相关阅读:
    170516、ActiveMQ 的安装与使用(单节点)
    170515、mybatis批量操作
    170512、java日志文件log4j.properties配置详解
    170511、Spring IOC和AOP 原理彻底搞懂
    170510、数据库默认隔离级别
    170509、文本编辑器编写的shell脚本在linux下无法执行的解决方法
    170508、忘记jenkins密码或者修改jenkins密码
    170505、MySQL的or/in/union与索引优化
    170504、MongoDB和MySQL对比(译)
    Jenkins Android 打包
  • 原文地址:https://www.cnblogs.com/suanec/p/3893755.html
Copyright © 2011-2022 走看看