标签:int \n ext app 字符 字符串 ucf sub tor
#给定一个字符串,比如char *str = /home/magic/DT/improved_trajectory/UCF-101/ApplyEyeMakeup/ApplyEyeMakeup_g01_c01.avi //我们的任务是得到最后的文件名,而且去掉后缀.avi,然后加上.txt string path = str; int p = path.find_last_of("/"); string path_temp = path.substr(p+1); //得到path_temp = ×××××.avi int q = path_temp.rfind(".avi"); //从后往前找 string path_txt = path_temp.substr(0, q) +".txt"; //得到ApplyEyeMakeup_g01_c01.txt
//另外,附上C的版本
char filename[100]="/home/magic/DT/improved_trajectory/UCF-101/ApplyEyeMakeup/ApplyEyeMakeup_g01_c01.avi"; char *extr=strrchr(filename,‘.‘); if (extr) { *extr=‘\0‘; extr++; } printf("name=%s\n", filename); printf("extr-name=%s\n", extr); return 0;
标签:int \n ext app 字符 字符串 ucf sub tor
原文地址:https://www.cnblogs.com/logo-88/p/9465384.html