Suppose you have a table of characters like this:
set tCode to paragraphs of "+++++++
[>+++++++++<-]
>.<+++++
[>++++++<-]
>-.+++++++..+++.
<++++++++
[>>++++<<-]
>>.<<++++
[>------<-]
>.<++++
[>++++++<-]
>.+++.------.
--------.>+."
and want to check that it contains only characters from an approved list:
set codeChars to {">", "<", "+", "-", ".", ",", "[", "]"}
The easy way to do that is to use the allowable code characters list as an AppleScript text item delimiter:
-- Put the program in list form:
set tCode to paragraphs of "+++++++
[>+++++++++<-]
>.<+++++
[>++++++<-]
>-.+++++++..+++.
<++++++++
[>>++++<<-]
>>.<<++++
[>------<-]
>.<++++
[>++++++<-]
>.+++.------.
--------.>+."
set codeChars to {">", "<", "+", "-", ".", ",", "[", "]"}
-- Check for valid characters in code, i.e. all in codeChar.
-- Use list of code characters as delimiter. Rather than
-- concatinate them all and check that (which works), better to
-- use a loop so the offending line can be identified.
repeat with k from 1 to count tCode
set codeItem to item k of tCode
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to codeChars
set tParts to text items of codeItem -- should all be ""
set AppleScript's text item delimiters to tid
-- "tParts as text" reduces to "" if all code text is in codeChar
if (count characters of (tParts as text)) ≠0 then
display alert "Line " & k & " contains an illegal code character!" as warning
return
end if
end repeat