简体   繁体   English

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

[英]finding last occurrence using boost string

How can I obtain similar functionality with 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);      

Above code( QT based) finds the name of the file without extension , md is an object , filepath, title are QString . 上面的代码(基于QT)查找没有扩展名的文件名,md是一个对象,文件路径,标题是QString。 I have browsed boost's string methods like find_last but it returns iterator_range. 我已经浏览了boost的字符串方法,例如find_last,但它返回了iterator_range。 I m new to boost , thanks in advance . 我是新来提高的,预先感谢。

If all you want to do is filename parsing then you'd be better off using the boost::filesystem::path class. 如果您要做的只是文件名解析,那么最好使用boost::filesystem::path类。 In particular the following methods: 特别是以下方法:

path filename() const;

path stem() const; and

path extension() const;

The class provides conversions to and from std::string and std::wstring . 该类提供与std::stringstd::wstring

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM