Re: Beginner need help!!!!!
The following is a very simple-minded approach. Depending on your purposes, though, it might be enough:
Code:
public string sanitizeString(string initial, string[] prohibitedWords)
{
string[] tokens = initial.Split(' '); //Split the string into tokens by spaces
System.Text.StringBuilder result = new System.Text.StringBuilder();
for(int i = 0; i < tokens.Count; i++)
{
//Only add non-prohibited tokens to the result string
if( !arrayContainsToken(tokens[i], prohibitedWords) )
{
result.Append(token[i]);
result.Append(" ");
}
}
return result.ToString();
}
bool arrayContainsToken(string token, string[] prohibitedWords)
{
//Returns true if token is in the list of prohibited words
}
Also, try to avoid any clbuttic mistakes: http://www.codinghorror.com/blog/200...-bad-idea.html
Re: Beginner need help!!!!!
Words meaning separated by a space? (Note: you'll have to trim out the delimiters in case someone types in "badword!" for example. "badword" != "badword!". Or in-string values as well? "somethingbadwordsomething"?
Check using IndexOf() and perhaps check if there is a space before the found word at the index returned by IndexOf() - 1. If at the beginning of the user-input, then keep in mind to not check the index before as 0 - 1 = -1, and -1 would be invalid as an index for a string.
Quote:
Can you post the full Code !!!!
No... I don't write code for others, I just help. We need more clarity however on what your guidelines are, as there's probably many things that you and others have not thought about. If, just anywhere in the string you don't want these words, regardless of their surrounding characters, then IndexOf() would work perfectly.
Code:
"String value".IndexOf('v', StringComparison.OrdinalIgnoreCase);
Use a StringComparison option for case insensitive validation (assuming you want case insensitivity here).
I am willing to help, but if you just want code, then I'm probably not the right person you're looking for.
~Ace