Need to check this with other strings, debug some more, improve comments and string handling in main(), etc. But still....here it goes:
#include "stdafx.h"
const wchar_t whitechar = ' ';
const bool IncludeWhiteSpace = true;
const wchar_t* wordstoremove[] = {L"dog", L"cat"};
const wchar_t* strtoparse = L"dog cat monkey dog horse dog"; //Len 28
int ltoparse;
const int numwords = 2;
int wordlen[numwords];
//Positions in the original string to rip
int pos_orig_from;
int pos_orig_to;
//Len of left and right copies
int left_len;
int right_len;
//Gets hoy many bytes per char
void ProcessLeft(wchar_t* strresult)
{
bool bContinue = true;
pos\_orig\_from = left\_len = 0;
while (bContinue)
{
//Check for whitespaces. If there are, copy them
if (strtoparse\[pos\_orig\_from\] == whitechar)
{
pos\_orig\_from ++;
if (IncludeWhiteSpace)
{
strresult\[left\_len\] = whitechar;
left\_len ++;
}
}
else
{
bContinue = false;
for (int i = 0; i < numwords; i++)
{
//Compare strings
wchar\_t\* strcompare = (wchar\_t\*)strtoparse + pos\_orig\_from;
if (wcsncmp(strcompare, wordstoremove\[i\], wordlen\[i\]) == 0)
{
pos\_orig\_from += wordlen\[i\];
bContinue = true;
break;
}
}
}
}
}
void ProcessRight(wchar_t* strresult)
{
bool bContinue = true;
pos\_orig\_to = right\_len = ltoparse - 1;
while (bContinue)
{
//Check for whitespaces. If there are, copy them
if (strtoparse\[pos\_orig\_to\] == whitechar && IncludeWhiteSpace)
{
pos\_orig\_to -= 1;
if (IncludeWhiteSpace)
{
strresult\[right\_len\] = whitechar;
right\_len -= 1;
}
}
else
{
bContinue = false;
for (int i = 0; i < numwords; i++)
{
//Compare strings
//To check right, start from end and substract string to compare len
wchar\_t\* strcompare = (wchar\_t\*)strtoparse + pos\_orig\_to - wordlen\[i\] + 1;
if (wcsncmp(strcompare, wordstoremove\[i\], wordlen\[i\]) == 0)
{
pos\_orig\_to -= wordlen\[i\];
bContinue = true;
break;
}
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
//Load len of words to avoid rechecking
for (int i=0; i