How can I check each character in a character array against a string? For example, I want to check these characters: !,@,#,$,%,^,&,*,(,),_,+ against the string af!a$co. Without regex, though.
Does this make sense?
public boolean IllSymbols(String newString)
{
char [] data = {'!', '#', '$', '%', '^', '&', '*', '(', ')' };
String str = new String(data);
for (int i=0; i<str.length(); i++)
{
for (int j=0; j<local.length(); j++)
{
if (str.charAt(i)==local.charAt(j))
{
return true;
}
}
}
return false;
}
But when I check the word af!a$co in my main method
if (IllSymbols(newString)==true)
{
return false; // false = text is illegal
}
else
{
return true; // true = text is legal
}
The devil returns the string as 'true', meaning that it's a legal string. Maybe I'm doing something wrong?
return !IllSymbols(newString);. Complex boolean logic, huh? :)