A question about 'word'...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

A question about 'word'...

Post by bogs » Sun Feb 10, 2019 2:21 pm

I have a label with a tab and a word in the contents section like so -
Selection_007.png
Word UP!
Selection_007.png (9.88 KiB) Viewed 3807 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...
Selection_008.png
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 Image
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10099
Joined: Fri Feb 19, 2010 10:17 am

Re: A question about 'word'...

Post by richmond62 » Sun Feb 10, 2019 3:00 pm

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
Screenshot 2019-02-10 at 15.59.55.png (22.2 KiB) Viewed 3800 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".
Attachments
field2var.livecode.zip
Here's the stack
(1.02 KiB) Downloaded 180 times

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: A question about 'word'...

Post by bogs » Sun Feb 10, 2019 3:07 pm

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' :D

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.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: A question about 'word'...

Post by FourthWorld » Sun Feb 10, 2019 3:17 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: A question about 'word'...

Post by bogs » Sun Feb 10, 2019 4:05 pm

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
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10049
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: A question about 'word'...

Post by FourthWorld » Sun Feb 10, 2019 6:27 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: A question about 'word'...

Post by bogs » Sun Feb 10, 2019 9:51 pm

Gotcha! :D
Image

Post Reply