BL> Is a case insensitive check possible, or can I uppercase
BL> the incoming file line to make the comparison?
BL> // Loop through the source file, checking each line for the
BL> // offending text, and writing those that pass the "filter"
BL> // to the output working file.
BL> while (!infile.eof())
BL> {
BL> infile.getline(buff, sizeof(buff));
BL> if (strstr(buff, "DESCRIPTION BY DIZMAN") == 0)
BL> outfile << buff << endl;
BL> else
BL> cntr + 1;
BL> }
You can construct a simple function to do the comparison.
int ci_strstr(char *pszStr, char *pszCmp)
{
if(!pszStr || !pszCmp || !*pszStr || !*pszCmp)
return -1;
int iStr = strlen(pszStr + 1), iCmp = strlen(pszCmp + 1);
char *pszUStr = new char[iStr], *pszUCmp = new char[iCmp];
for(;iCmp >= 0; iCmp--)
pszUCmp[iCmp] = char(toupper(pszCmp[iCmp]));
for(;iStr >= 0; iStr--)
pszUStr[iStr] = char(toupper(pszStr[iStr]));
char *pcFound = strstr(pszUStr, pszUCmp);
int iResult = pcFound ? pzsUStr - pcFound + 1 : 0;
delete []szUStr;
delete []szUCmp;
return iResult;
}
This will test the strings submitted for comparison, then
create upper case strings from both, and return the results
of a strstr() comparison of the two. If you are interested in
whether there is a viable result, a negative number is
returned in the event of an error. The pointer, if needed, to
the point at which the secondary string is contained within
the primary string, may be reconstituted from the int
returned, added to the string given, minus one.
In your case, you would only be interested in whether the
value were greater than zero, though.
You could use this to replace offensive words with less
objectionable character sequences also, however.
For instance, if you were opposed to the word QBasic,
considering it to be a profanity:
if((found = ci_strstr(buffer, "qbasic")) > 0)
{
char *temp = new char[strlen(buffer) + 1];
buffer[found] = (char)'\0';
sprintf(temp, "%s%s%s",
buffer, "Q@!*%$", buffer + found + 6);
delete []buffer;
buffer = temp;
}
As always, you could include all of this in your own String
class and have it available for all text operations using
strings.
> ] Once you know me better, you'll like me even less...........
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)
|