Re: Xpress offset of tab giving an unexpected result.
Re: Xpress offset of tab giving an unexpected result.
- Subject: Re: Xpress offset of tab giving an unexpected result.
- From: Hans Haesler <email@hidden>
- Date: Wed, 8 May 2002 14:32:06 +0200
On Wed, 8 May 2002, email@hidden wrote:
>
I have a text box in Xpress. It contains (for example):
>
>
abcd<tab>abcd<tab>abcd<tab>abcd<return>
>
>
set bnTab to (offset of every character where it is "\t") as list
>
>
In the above example, this returns {{0},{4},{9},{14},{19}}
>
>
Which is wrong, to me, in three ways
>
>
1. Item 0 doesn't exist
>
2. It's a list of lists
>
3. It's a character out.
Steve,
1. The numbers in the list are the _offsets_ of the tabs.
In other words, they say how many characters are _before_ each
tab, and counted from the beginning of the story.
The '0' means that the story begins with a tab. There are no
other characters before it. Hence the '0'.
2. Just omit 'as list'. Then the result is: {0, 4, 9, 14, 19}
But if there is only one tab, then the result is not a list
but an integer. And when your script tries to get 'item 1 of bnTab'
then this generates an error.
To avoid this the script can test the class of 'bnTab'. If it isn't
'list' then it coerces 'bnTab' to a list:
---
if class of bnTab is not list then set bnTab to {bnTab}
---
3. See point one. The value is not the position of the tab
but the number of characters _before_ it.
---
Hans Haesler <email@hidden>
_______________________________________________
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.