CString中保存的是路径和文件名,请问如何提取其中的文件名? 比如 CString strPathName= "C:\\abc\aaa.txt";如何提取其中的aaa.txt ??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用CString的ReverseFind查找'\'然后,使用CString的Right提取 CString strPathName= "C:\\abc\aaa.txt"; 这是不对的,应该是CString strPathName= "C:\\abc\\aaa.txt"; 用CString的ReverseFind函数即可。int nIdx = strPathName.ReverseFind('\\');CString sName = strPathName.Mid(nIdx+1); CString strPathName = "C:\\abc\\aaa.txt"; CString strName = strPathName.Right(strPathName.ReverseFind('\\') + 1); 请问怎么查找CString的ReverseFind查找'\'是不是 int nPos = strPathName.ReverseFind('\\');可是找出的位置 nPos = 2,显然不对? 不是说了么,CString strPathName= "C:\\abc\aaa.txt"; 这是不对的,应该是 CString strPathName= "C:\\abc\\aaa.txt"; ReverseFind返回的是从尾部往前倒着找到的索引号所以这里应该是:CString strPathName= "C:\\abc\aaa.txt"; 这是不对的,应该是 CString strPathName= "C:\\abc\\aaa.txt"; int nIdx = strPathName.ReverseFind('\\'); CString sName = strPathName.Mid(strPathName.Length() - nIdx+1);//这里用字符串长度减去尾部数起的索引号就是正向的索引号. MFC 多人利用DLL协同开发 BtnST的问题 为什么我的vc6有时候编译的时候就无法停止了? 【急】请问如何在程序里修改系统属性里面的设置啊,解决了就给分,分不够也可以再加,谢谢!!! 一个月赚800! 搞过数据包分段再重组的达人进(300分) 调试错误 什么activeX控件可以显示gif图像? 如何使DC透明化 C++类的问题 关于获取字符串尺寸不准确的问题 SDI里,Frame 调用 View
CString strPathName= "C:\\abc\\aaa.txt";
用CString的ReverseFind函数即可。
int nIdx = strPathName.ReverseFind('\\');
CString sName = strPathName.Mid(nIdx+1);
CString strName = strPathName.Right(strPathName.ReverseFind('\\') + 1);
CString strPathName= "C:\\abc\aaa.txt"; 这是不对的,应该是
CString strPathName= "C:\\abc\\aaa.txt";
所以这里应该是:CString strPathName= "C:\\abc\aaa.txt"; 这是不对的,应该是
CString strPathName= "C:\\abc\\aaa.txt"; int nIdx = strPathName.ReverseFind('\\');
CString sName = strPathName.Mid(strPathName.Length() - nIdx+1);//这里用字符串长度减去尾部数起的索引号就是正向的索引号.