使用boost字符串查找最后一次出现

时间:2012-05-11 09:14:09

标签: c++ string boost

如何使用boost

获得类似的功能
  int idx = md.filepath.lastIndexOf('/');                                 
      md.title = md.filepath.right(md.filepath.length() - idx -1);            
      md.title = md.title.left(md.title.length() - 4);      

上面的代码(基于QT)查找没有扩展名的文件名,md是一个对象,filepath,title是QString。我浏览了像find_last这样的boost字符串方法,但它返回了iterator_range。我很想提升,谢谢你。

1 个答案:

答案 0 :(得分:3)

如果您只想做文件名解析,那么最好使用boost::filesystem::path类。特别是以下方法:

path filename() const;

path stem() const;

path extension() const;

该课程提供与std::stringstd::wstring之间的转化。

相关问题