如何在字符右侧的QString中查找元素(How to find elements in a QString to the right of a character)

编程入门 行业动态 更新时间:2024-10-24 18:22:05
如何在字符右侧的QString中查找元素(How to find elements in a QString to the right of a character)

我有一个文件名作为QString,它看起来像“c:/ ..... /whatIAmActuallyInterestedIn.stuff”

我想在最后/之后获得所有信息,在这种情况下,这将是whatIAmActuallyInterestedIn.stuff

现在,我知道我可以将它转换为std :: string,使用rfind查找字符串中的最后一个/,然后将其转换回QString进行输出。 但是,这看起来像是为了我相当确定的QString内置的东西做了大量的工作,我找不到函数调用。

I have a filename as a QString which looks like "c:/ ..... /whatIAmActuallyInterestedIn.stuff"

I want to get all the information after the last /, which in this case would be whatIAmActuallyInterestedIn.stuff

Right now, I know that I can convert this to a std::string, use rfind to find the last / in the string, and then convert it back to a QString for then outputting. However, this seems like doing an excessive amount of work for something that I am fairly certain QString has built in, I just can't find the function call.

最满意答案

您可以像这样提取文件名:

QFileInfo("c:/ ..... /whatIAmActuallyInterestedIn.stuff").fileName();

You can extract the file name like this:

QFileInfo("c:/ ..... /whatIAmActuallyInterestedIn.stuff").fileName();

更多推荐

本文发布于:2023-07-26 02:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   元素   如何在   elements   character

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!