Qt中字符串截取

来源:互联网 发布:mac怎么关闭隐藏文件 编辑:程序博客网 时间:2024/06/05 08:00

QString str = "D:/Users/xxx/hello.png";//原始字符串

int index = str.lastIndexOf('/');//查找最后一次出现'/'在字符串中的索引,结果为index=12;

QString str1 = str.mid(0,index+1);//截取字符串str,起始索引位置为0,截取字符的个数为index+1,结果为str1="D:/Users/xxx/";

QString str2 = str.mid(index+1);//截取字符串str,起始索引位置为index+1,截取字符到字符串结束,结果为str2="hello.png";

原创粉丝点击