find text in string

set tText to "itunes.apple.com/us/app"
set weblocURL to "http://www.yelp.com/biz/the-monks-kettle-san-francisco"

repeat with weblocURL in paragraphs of tText
	if tText is in weblocURL then display dialog weblocURL & " is in Web Location"
end repeat

trying to check if a text string is in a long string. The example above should not say it’s in the string but it does.

any help would be appreciated.

working code.

set tText to "itunes.apple.com/us/app"
set weblocURL to "http://www.yelp.com/biz/the-monks-kettle-san-francisco"

set existTag to tText is in weblocURL
if existTag then
	display dialog tText & " is in Web Location"
else
	return
end if

It does because you’re using weblocURL as index variable of the repeat loop and as reference string. At the beginning of the repeat loop weblocURL is overwritten with “itunes.apple.com/us/app” so the evaluation returns true

In other words, you need to change your repeat with variable to an unused variable.

set tText to {"itunes.apple.com/us/app", "http://www.yelp.com"}
set weblocURL to "http://www.yelp.com/biz/the-monks-kettle-san-francisco"

repeat with aText in tText
	set aText to aText as text
	if aText is in weblocURL then display dialog aText & " is in Web Location"
end repeat

The as text coercion is not needed :slight_smile:

From one of my templates in Script Debugger. I usually use contents of or as text in repeat loops to avoid problems from manipulating variables down the line.

Basically you’re right, but explicit dereferencing of list items is needed only for the equality (and inequality) operator

As Stefan already mentioned,it is needed in some cases. Maybe I should explain why it isn’t in this case: AppleScript will look at the right object of the is in operator and when that object is string, it will coerce the object on the left of the operator for you into a string. Like objects right of the ampersand (concatenation) are automatically coerced into the same class as on the left of the ampersand, otherwise it’ll return a list.