zoukankan      html  css  js  c++  java
  • C++ 常用的字符串处理函数实现

    以下是一些标准库没有实现的函数,我觉得很方便就写了,估计会不定时更新。

     1  //根据一个文件的路径获取文件名
     2   
     3  std::string file_name(const std::string& path)
     4  {
     5       return path.substr(path.find_last_of("/\") + 1);
     6   }
     7   
     8    
     9   
    10  //根据一个文件的路径获取该文件的路径
    11  
    12  std::string base_name(const std::string& path)
    13  
    14  {
    15 
    16  }
    17 
    18 
    19 
    20  //根据一个文件的路径获取该文件的扩展名
    21  
    22  std::string file_extension(const std::string& path)
    23 
    24  {
    25 
    26   std::string::size_type idx;
    27 
    28  idx = filename.rfind('.');
    29 
    30  return (idx != std::string::npos) ? filename.substr(idx+1) : "";
    31 
    32  }
    33 
    34 //C++ 字符串分隔
    35 std::vector<std::string> split(const std::string& input, const std::string& regex) {
    36     // passing -1 as the submatch index parameter performs splitting
    37     std::regex re(regex);
    38     std::sregex_token_iterator
    39         first{ input.begin(), input.end(), re, -1 },
    40         last;
    41     return{ first, last };
    42 }
  • 相关阅读:
    AGC044D Guess the Password
    CF1290E Cartesian Tree
    loj2537. 「PKUWC2018」Minimax
    loj3166. 「CEOI2019」魔法树
    CF702F T-Shirts
    CF1260F Colored Tree
    CF1340F Nastya and CBS
    CF1017G The Tree
    CF150E Freezing with Style
    前端开发 -- HTML
  • 原文地址:https://www.cnblogs.com/foohack/p/5553674.html
Copyright © 2011-2022 走看看