Page 1 of 1
A question about 'word'...
Posted: Sun Feb 10, 2019 2:21 pm
by bogs
I have a label with a tab and a word in the contents section like so -

- Word UP!
- Selection_007.png (9.88 KiB) Viewed 3813 times
I want to get that word into a variable (which I did figure out a way to do it), but am curious why this code produced the result it did.
My initial code was -
Code: Select all
if word 1 of the target is "Image" then put word 2 of the name of the target into tmpPick
You can see that the code (kinda) did what I was expecting, but it also placed the tab preceding the word into the variable...

- Huh, I never made the connection...
Now, the way I read the dictionary entry on 'word' ....
A word is delimited by one or more spaces, tabs, or returns, or enclosed by double quotes. A single word can contain multiple characters and multiple items, but not multiple lines.
the word is delimited by a number of means, including (in this case) a tab, but why would it include the tab in the variable? The tab, even though part of a string, isn't part of a word is it?
I don't think tab falls under the "multiple characters" part of the definition since when I used characters to define the variable, character 1 didn't come back as the tab.
I iz confuzzled

Re: A question about 'word'...
Posted: Sun Feb 10, 2019 3:00 pm
by richmond62
I dunno . . .
BUT why does your code put the second word of the title of your object into a variable
rather than the word contained inwith your field?
-

- Screenshot 2019-02-10 at 15.59.55.png (22.2 KiB) Viewed 3806 times
-
Code: Select all
on mouseUp
put word 1 of fld "f1" into FV
put FV into fld "f2"
end mouseUp
Note that field "f1" contains a TAB followed by the word "cheese".
Re: A question about 'word'...
Posted: Sun Feb 10, 2019 3:07 pm
by bogs
richmond62 wrote: ↑Sun Feb 10, 2019 3:00 pm
BUT why does your code put the second word of the title of your object into a variable
rather than the word contained inwith your field?
That is part of what I am trying to figure out about 'word'
This actually is the code I wound up going with -
Code: Select all
if word 1 of the target is "Image" then put word 1 to 2 of the short name of the target into tmpPick
if the short name of the target begins with "lbl" then
set the backgroundColor of the target to "blue"
set the textColor of the target to "white"
put word 1 to 2 of the text of the target into tmpPick
end if
but it is going into a script local variable because it will be used later in other handlers.
Re: A question about 'word'...
Posted: Sun Feb 10, 2019 3:17 pm
by FourthWorld
Immediate solution: use trueword rather than word to get exactly what you're looking for.
Long term solution: file a bug report so either the Dictionary or the functionality of word can be tuned.
Re: A question about 'word'...
Posted: Sun Feb 10, 2019 4:05 pm
by bogs
Yah, I think I just need to get used to using 'trueWord' more often.
Here is what I (think) is going on, based on my previous question with control names -
I was looking for word 2 of the name
word 2 is enclosed in quotes
Lc interprets this as one 'word', even though it contains a tab
so when you ask for word 1 "of word 2 of the name" it gives you the 2nd word minus the tab.
I'm just not sure if that is how it is supposed to interpret it? I'll follow your advice and (if it is happening in 8.1.x) submit a bug report for clarification.
*Edit - it was fixed somewhere on the way to vers. 8.x, so no bug report needs to be filed
*Edit 2 - Heh, now I remember why I don't think about 'trueWord' much -
summary
Designates a string as part of a chunk expression, delimited by Unicode word breaks, as determined by the ICU Library.
introduced
7.0
Re: A question about 'word'...
Posted: Sun Feb 10, 2019 6:27 pm
by FourthWorld
Looks like I've provided another opportunity for Klaus to remind me to read all of the details in a thread before replying.
It all seems to be working as expected, given the quotes around word 2 of the source string.
To simplify this, let the engine do the parsing: instead of getting the name of the object, get the short name.
Re: A question about 'word'...
Posted: Sun Feb 10, 2019 9:51 pm
by bogs
Gotcha!
