Get File Extension from an URL stored in CString
//COMMENT: This method takes an URL ( eg: http://www.abc-website.com/images/background.gif) as an argument and returns .gif as an extension.
CString getFileExtension(CString fileName)
{
CString ch=L".";
int totalLength=fileName.GetLength();
int idxOfDot=fileName.Find(ch,totalLength-5);
CString fileExtn=fileName.Mid(idxOfDot,(totalLength-idxOfDot)); // totalLength-1 because index is zero based.
return fileExtn;
}
Swap two entries in a std::vector
// COMMENT: The following code snippet swaps two rows in a std::vector
// Each entry in this vector is a pointer to an UrlData object.
void swapRows(int swapFrom, int swapTo)
{
vector<UrlData *>::iterator itr=getUrlVector()->begin();
if(swapTo > swapFrom)
{
UrlData* rowRemoved=getUrlVector()->at(swapTo);
getUrlVector()->erase(itr+swapTo);
getUrlVector()->insert(itr+swapFrom,rowRemoved);
}
else
{
UrlData* rowRemoved=getUrlVector()->at(swapFrom);
getUrlVector()->erase(itr+swapFrom);
getUrlVector()->insert(itr+swapTo,rowRemoved);
}
}
//COMMENT: This method takes an URL ( eg: http://www.abc-website.com/images/background.gif) as an argument and returns .gif as an extension.
CString getFileExtension(CString fileName)
{
CString ch=L".";
int totalLength=fileName.GetLength();
int idxOfDot=fileName.Find(ch,totalLength-5);
CString fileExtn=fileName.Mid(idxOfDot,(totalLength-idxOfDot)); // totalLength-1 because index is zero based.
return fileExtn;
}
Swap two entries in a std::vector
// COMMENT: The following code snippet swaps two rows in a std::vector
// Each entry in this vector is a pointer to an UrlData object.
void swapRows(int swapFrom, int swapTo)
{
vector<UrlData *>::iterator itr=getUrlVector()->begin();
if(swapTo > swapFrom)
{
UrlData* rowRemoved=getUrlVector()->at(swapTo);
getUrlVector()->erase(itr+swapTo);
getUrlVector()->insert(itr+swapFrom,rowRemoved);
}
else
{
UrlData* rowRemoved=getUrlVector()->at(swapFrom);
getUrlVector()->erase(itr+swapFrom);
getUrlVector()->insert(itr+swapTo,rowRemoved);
}
}