Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Need help again.. I am trying to find spam words.

I have a string str1 which contains subject of mail
and i have another string str2 which contains the message of mail

Then i have another string strspam which contains spam word list

Now i have to find whether the string is str1 is in stspam likewise str2 in strspam....


Please help me out...Thanks in advance

[edit]Urgency deleted - OriginalGriff[/edit]
Posted
Updated 15-Jun-12 18:37pm
v2
Comments
OriginalGriff 16-Jun-12 0:37am    
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.
Arjun Menon U.K 16-Jun-12 0:50am    
Ok Original Griff wont place urgent in the content again.. My apologies

1 solution

You need to separate the "spam words" into separate strings. Assuming they are separated by spaces:
C#
string[] spamWords = stringOfSpamWords.Split(' ');

You can then do it pretty easily with Linq:
C#
if(spamWords.Any(s => stringToCheck.Contains(s)))
   {
   ...
   }
 
Share this answer
 
Comments
Arjun Menon U.K 16-Jun-12 1:02am    
Can you specify the code u gave above using Linq. The spamWords string array contains the spam word list rt? the variable s and stringToCheck contains what all values?
OriginalGriff 16-Jun-12 1:13am    
Input: stringOfSpamWords
First line breaks this into an array of strings, in spamWords
"s" is a Linq placeholder, it will hold each of the strings in spamWords in turn as Linq processes the array.
stringToCheck - the clue is in the name...holds the string you want to check if it contains any words on your spam list...
Arjun Menon U.K 16-Jun-12 1:24am    
Thanks Original Griff it worked fine....Cheers Bro...
Arjun Menon U.K 18-Jun-12 3:03am    
Using Linq slows down the process right?
OriginalGriff 18-Jun-12 3:28am    
Linq can be slower than other methods, depending on what you are doing.
Regex is generally faster, BUT... (and it is a big but) ... Linq can be a lot faster than other methods depedning on what you are doing.
In this case, the one line of Linq code replaces a loop with sting.Contains in, which is impractical to do in a regex.
The way to find out is to test it: Write the Linq as a method, write an alternative as a method, and time them both. It can be surprising what results you actually get.
Have a look at this:
http://www.codeproject.com/Tips/312312/Counting-lines-in-a-string
And remember, it isn't doing anywhere near as complex a job as your code will have to!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900