Re: Understanding a repeat loop (strings/characters)
Re: Understanding a repeat loop (strings/characters)
- Subject: Re: Understanding a repeat loop (strings/characters)
- From: has <email@hidden>
- Date: Sun, 23 Feb 2003 01:35:12 +0000
Paul Skinner wrote:
> I'm trying to understand what is happening here:
>
> set theString to (call method "getThing")
> log (class of theString as string) -- "Unicode text"
> repeat with theChar in theString
> -- do things with each character
> end repeat
>
> The "repeat with" loops once for each character of theString, and
> that's what I want to happen. But, since theString is not a list, can
> somebody explain why the loop variable is fed each character rather
> than the entire string?
>
> Jeff
Because your use of the 'repeat with foo in bar' structure implies that
bar is a list that AS can repeat through. It's not; but certain data
types can be coerced to a list; so AS does this silently.
Incorrect. The 'repeat with itemRef in val' structure iterates over
an object's items. Both strings and lists have 'item' elements, so
either may be used here. And since in strings 'item' is synonymous
with 'character', what you end up with is a reference to each
character.
has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.