VC中,有一个CString类型的字串,想去掉未尾的若干个字符,怎么做? 若有cstring str="d:\aa\aa.txt"我想删除未尾的"\aa.txt"等七个字符,得到CString str2="d:\aa"怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString str1="d:\aa\aa.txt";CString str2=str1.Delete(5, 7); CString有一个find()的方法,找到标志字符的位置,用left()之类的方法就可以了 首先确定你要去掉字符的开始位置:int n = str.ReverseFind(_T('\\'));然后:str = str.Left(str.GetLength() - n ); CString Mid( int nFirst ) const;throw( CMemoryException );CString Mid( int nFirst, int nCount ) const;throw( CMemoryException ); 我提的问题不是这个,我的意思是能确定最后若干位,如:f:\aa\aaa.txt我能确定aaa.txt,现在我想去掉f:\aa\aaa.txt未尾的\aaa.txt的八个字符,怎么做,前面的字符个数不能确定。 ReverseFind,look more on msdn CString str="d:\aa\aa.txt"str.Delete(5,7);AfxMessageBox(str); 哦,前面的不确定啊,那先服从“ stavck(关未明)”然后再搞 CString str1,str2;int m,n; str1="f:\aa\aaa.txt"; str2="\aaa.txt"; m=str2.GetLength(); n=str1.GetLength(); str1.Delete(n-m,m);你愿意确定什么确定什么吧 呵呵,刚上CSDN来准备问同一个问题,就发现楼主的贴子了,楼主不会正好也在取得文件路径吧? 这样吧:str = str.Left(str.GetLength() - 7); ScreenToClient为什么转出来的坐标值会是负数 怎样通过接口获得<META >中的内容? EDIT的问题? 求VC6的MSDN下载地址 如何在win32应用程序中使用richedit20控件? 我用VC++的MFC ODBC操作数据库的时候。可等我的应用程序操作结束后却出现一数据库临时文件 customer.ldb 文件? CString是否有长度限制? 关于控件ID(动态生成)的问题 共享打开数据库文件,应注意哪些问题? 看看这个类声明 如何搜索注册表? .ax什么东西啊,AppWizard怎么没有生成MyProject.ax的向导啊!
CString str2=str1.Delete(5, 7);
int n = str.ReverseFind(_T('\\'));
然后:
str = str.Left(str.GetLength() - n );
throw( CMemoryException );CString Mid( int nFirst, int nCount ) const;
throw( CMemoryException );
f:\aa\aaa.txt
我能确定aaa.txt,现在我想去掉f:\aa\aaa.txt未尾的\aaa.txt的八个字符,怎么做,前面的字符个数不能确定。
str.Delete(5,7);
AfxMessageBox(str);
int m,n;
str1="f:\aa\aaa.txt";
str2="\aaa.txt";
m=str2.GetLength();
n=str1.GetLength();
str1.Delete(n-m,m);你愿意确定什么确定什么吧
楼主不会正好也在取得文件路径吧?
str = str.Left(str.GetLength() - 7);