C风格:
1
char *p = strrchr(path.c_str(), '/')
p是path里最后一个'/'的地址。然后
1
string s(p + 1);
,s就是"world.shp"了。
C++风格:
1
int pos = path.find_last_of('/');
pos就是最后一个'/'的下标。
然后
1
string s(path.substr(pos + 1) );
s就是"world.shp"了。
CString GetFileName(CString sFullName)
{
CString s(sFullName);
int nPos = s.ReverseFind(_T('\\'));
if (nPos != -1)
s.Delete(nPos, s.GetLength() - nPos);
return s;
}
调用方法 CString fn = GetFileName(ss);
iPos = ss.ReverseFind(_T("\"));
CString str = ss.Right(ss.GetLength() - iPos - 1);