Qt----[字符串分割,提取]

1.獲取("C:/Users/test/Desktop/app"

QString appPathAndName= "C:/Users/test/Desktop/app/test.exe";
  • 方法一:
    qDebug()<<appPathAndName.left(appPathAndName.lastIndexOf("/"));

     

  • 方法二:
    QString exeName=appPathAndName.section('/', -1);
    int index = appPathAndName.lastIndexOf(exeName);
    appPath = appPathAndName.section("",0,index-2,flag);
    
    #appPath===="C:/Users/test/Desktop/app"
    #exeName===="test.exe"

     

2.去掉file:///

QString appPathAndName= "file:///C:/Users/test/Desktop/app/test.exe";
QString absoluteFilePath = filepath.remove(0,8); //去掉 "file:///"

3.時間日期提取

QString _year = "2015年";
int year = _year.left(_year.length-1);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章