Get the length of the path (not the filename)
-
Gets the offset of the last backslash of a path. :omg: Enjoy!!
int PathLen( LPCWSTR sWholePath)
{
CString sTmp(sWholePath),sTmp2;
int iPos=sTmp.Find('\\'),iStart=iPos+1;
while(1)
{
sTmp2=sTmp.Mid(iStart);
iPos=sTmp2.Find('\\');
if(iPos >= 0)
iStart+=(iPos+1);
else
break;
};
return iStart;
}; -
Gets the offset of the last backslash of a path. :omg: Enjoy!!
int PathLen( LPCWSTR sWholePath)
{
CString sTmp(sWholePath),sTmp2;
int iPos=sTmp.Find('\\'),iStart=iPos+1;
while(1)
{
sTmp2=sTmp.Mid(iStart);
iPos=sTmp2.Find('\\');
if(iPos >= 0)
iStart+=(iPos+1);
else
break;
};
return iStart;
};Bah! Go recursive! :-D
-
Gets the offset of the last backslash of a path. :omg: Enjoy!!
int PathLen( LPCWSTR sWholePath)
{
CString sTmp(sWholePath),sTmp2;
int iPos=sTmp.Find('\\'),iStart=iPos+1;
while(1)
{
sTmp2=sTmp.Mid(iStart);
iPos=sTmp2.Find('\\');
if(iPos >= 0)
iStart+=(iPos+1);
else
break;
};
return iStart;
};I think you guy has read a book about algorithms and optimizing them – overzealous with a weird way of thinking. “I go through the string from the first char through all the backslashes until there aren’t any” instead of “I go through the string from the last char until there is a backslash” Or maybe he was just trying to make things harder for anyone else that would look at the code... :laugh:
I have no smart signature yet...
-
I think you guy has read a book about algorithms and optimizing them – overzealous with a weird way of thinking. “I go through the string from the first char through all the backslashes until there aren’t any” instead of “I go through the string from the last char until there is a backslash” Or maybe he was just trying to make things harder for anyone else that would look at the code... :laugh:
I have no smart signature yet...
-
LastIndex is only more efficient if you already know how long the string string is. In C, that would have to scan the entire string and then back up, which is less efficient.
-
I think you guy has read a book about algorithms and optimizing them – overzealous with a weird way of thinking. “I go through the string from the first char through all the backslashes until there aren’t any” instead of “I go through the string from the last char until there is a backslash” Or maybe he was just trying to make things harder for anyone else that would look at the code... :laugh:
I have no smart signature yet...
Ohhhh, I've known many developers that write code harder because they think it looks cool. Unfortunately I've known WAY too many especially this fat pig that preached about how website development is very difficult; he then went on to develop a very difficult website. Mike's code was soooooooo bad that they have to run to instances of the website on the same machine to properly test it....according to him. He was also complaining about how hard it was to test his code after his iterative code went more than 30 levels deep.