一个字符串的问题,在线等待,高分请教,马上给分 CString str; str.Format("%s",buf); buf的内容为:c:\file\kkk.txt 我想建立一个文件夹c:\file,那我就要把c:\file读出来,我该怎么读的,请指点小弟一下,马上给分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果你是想只取出目录名,可以用CString的反向查找,找第一个"\",然后用CString的Left方法取左边m个字符就OK了 int pos=str.ReverseFind('\\');str=str.Left(pos); str[str.ReverseFind('\\')] = 0; 我也多次遇到这个问题,一般这样解决:int index = str.ReverseFind('\\');if (index > 0) CreateDirectory(str.Left(index+1)); //****************************************************************//分割pathName使之分为Path,Name,Extension//****************************************************************BOOL ParsePathName(CString &strPathName, CString& Path,CString &Name, CString &Ext){ int id=strPathName.GetLength()-1; if(id<0)return FALSE; Path.Empty(); Name.Empty(); Ext.Empty(); CString FileName; while(id>=0&&strPathName[id]!='\\') { FileName+=strPathName[id]; id--; } while(id>=0) { Path+=strPathName[id]; id--; } ConvertString(FileName); if(FileName.Find('.')!=-1) { id=FileName.GetLength()-1; while(id>=0&&FileName[id]!='.') { Ext+=FileName[id]; id--; } if(id>0) id--; while(id>=0) { Name+=FileName[id]; id--; } } else { Name=FileName; } ConvertString(Name); ConvertString(Path); ConvertString(Ext); return TRUE;}//*********************************************//按顺序反转字符串//*********************************************void ConvertString(CString& str){ int n=str.GetLength(); char temp; for(int i=0;i<n/2;i++) { temp=str[i]; str.SetAt(i,str[n-i-1]); str.SetAt(n-i-1,temp); }} 非常谢谢,我明白了,几位大哥,你们真厉害,我还想请教一个问题:c:\sunhao\sss\kkk.txt我只想要c:\sunhao,(是c:\sunhao\还是c:\sunhao)也就是第一个文件夹,我该怎么办? int pos=str.Find('\\',2);str=str.Left(pos); 或者int pos=str.Find('\\');pos=str.Find('\\',pos);str=str.Left(pos); 或者int pos=str.Find('\\');pos=str.Find('\\',pos);str=str.Left(pos); AC97以外的声卡都提示采集设备失败? 只要系统中有用到webbrowser这个activex就加载指定的dll,可以实现么? 新手请教一个小问题 在MFC中怎样获取当前程序所在的绝对路径? 高分求解:如何能够把一段文本打成UDP包发送出去? 我在应用程序里访问COM组件,COM组件通过ADO访问SQL数据库. 关于2k中.ico一问 vc运行时库文件的设置 创建COM(ATL)示例编译通不过 为什么ActiveX能调VBScript,却不能调JScript??? VC中自定义显示的视图不能用UpdateData函数?????????? 请帮忙看看开发一张多媒体光盘的程序员该提成多少?
str=str.Left(pos);
if (index > 0) CreateDirectory(str.Left(index+1));
//分割pathName使之分为Path,Name,Extension
//****************************************************************
BOOL ParsePathName(CString &strPathName, CString& Path,CString &Name, CString &Ext)
{
int id=strPathName.GetLength()-1;
if(id<0)return FALSE;
Path.Empty();
Name.Empty();
Ext.Empty();
CString FileName;
while(id>=0&&strPathName[id]!='\\')
{
FileName+=strPathName[id];
id--;
}
while(id>=0)
{
Path+=strPathName[id];
id--;
}
ConvertString(FileName);
if(FileName.Find('.')!=-1)
{
id=FileName.GetLength()-1;
while(id>=0&&FileName[id]!='.')
{
Ext+=FileName[id];
id--;
}
if(id>0) id--;
while(id>=0)
{
Name+=FileName[id];
id--;
}
}
else {
Name=FileName;
}
ConvertString(Name);
ConvertString(Path);
ConvertString(Ext);
return TRUE;
}
//*********************************************
//按顺序反转字符串
//*********************************************
void ConvertString(CString& str)
{
int n=str.GetLength();
char temp;
for(int i=0;i<n/2;i++)
{
temp=str[i];
str.SetAt(i,str[n-i-1]);
str.SetAt(n-i-1,temp);
}
}
c:\sunhao\sss\kkk.txt
我只想要c:\sunhao,(是c:\sunhao\还是c:\sunhao)也就是第一个文件夹,我该怎么办?
str=str.Left(pos);
int pos=str.Find('\\');
pos=str.Find('\\',pos);
str=str.Left(pos);
int pos=str.Find('\\');
pos=str.Find('\\',pos);
str=str.Left(pos);