Searching a string using 'where' filter for a character

I have found that using the ‘where’ reserved word to filter or search is much faster than manually stepping through a list to search for a match, such as:

tell application "Address Book"
	set theContacts to (get every person where ¬
		the first name is "Jon")
end tell

But recently I’ve been trying to use it find bad chars from a string like this:

property chars : {"a", "e", "i", "o", "u"}
property chars2 : "aeiou"

set newname to "Hello"
set badChars to (get every character in newname where it is in chars)
return badChars

but if I search using chars or chars2, it gives me back the error

whereas I think it should return the list {“e”, “o”}

Do I need to do some sort of coercion? I tried using “(it as character) is in chars” but that didn’t work either. Any ideas?

Thanks

No, you don’t need a “coercion”. You must use some sort of repeat loop to cycle through the ‘chars’ list for every ‘newname’ character you evaluate. Try something like this…

property chars : {"a", "e", "i", "o", "u", "Y"}
property badChars : {}

set newname to "Hello, I am usually called jobu... who are YOU?"

considering case
	repeat with tmpChar in (get every character in newname)
		if (chars contains tmpChar) and (badChars does not contain tmpChar) then
			set badChars to badChars & tmpChar
		end if
	end repeat
end considering

return badChars

j