zoukankan      html  css  js  c++  java
  • 根据文件的路径 分割文件名 文件后缀

    通过 CString.reverseFind 找到最后一个"\"的位置,

    然后根据这个CString.right 从右边1开始获取从右向左前 nCount 个字符,取到文件名。

    同理就可以取到后缀名了。

     1 CString strFilePathName = filename;
     2 CString strFullFileName, ExtendName;
     3 int Where;
     4 Where = strFilePathName.ReverseFind('\');
     5 if (Where == -1)
     6 {
     7    Where = strFilePathName.ReverseFind('/');
     8 }
     9 strFullFileName = strFilePathName.Right(strFilePathName.GetLength() - 1 - Where);
    10 int Which = strFullFileName.ReverseFind('.');
    11 ExtendName = strFullFileName.Right(strFullFileName.GetLength() - Which - 1);

     

    补充一下,CString实用分割方法:

      CString Left( int nCount ) const;                   //从左边1开始获取前 nCount 个字符

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

      CString Mid( int nFirst, int nCount ) const;    //从左边第 nFirst+1 个字符开始,获取后面  nCount 个字符

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

     

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

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

    在函数后面加 const 的意思是:如果一个类声明了一个常量对象,这个对象只能使用后边带 const 这个的方法.

     

    例:

     CString a,b;
     a = "123456789";


     b = a.Left(4);   //值为:1234
     b = a.Mid(3);    //值为:456789
     b = a.Mid(2, 4); //值为:3456
     b = a.Right(4);  //值为:6789

     参考文档 :http://blog.csdn.net/C_S_D_N_USER/article/details/27203181

  • 相关阅读:
    leetcode -- Triangle
    leetcode difficulty and frequency distribution chart
    leetcode -- Sqrt(x)
    leetcode -- Climbing Stairs
    leetcode -- Populating Next Right Pointers in Each Node II
    leetcode -- Populating Next Right Pointers in Each Node
    ThreadLocal
    Thread
    进程或者线程状态
    ThreadGroup
  • 原文地址:https://www.cnblogs.com/lhwblog/p/6425949.html
Copyright © 2011-2022 走看看