item 1+2

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
robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

item 1+2

Post by robm80 » Mon May 26, 2014 4:31 pm

Why does 1+2 goes wrong and 1+2+3 does nothing; have a look:

get "Foo, John,Westerveen 29,9751 HT,HAREN,,,,,,de Heer en Mevrouw; "
put item 1+2 of it

answer="Westerveen 29", but I expected "Foo John
put item 2+3 of it gives "Haren", also wrong, expected "John,Westerveen 29""


But asking for more items like items 2+3+4 does nothing.

Why?

Klaus
Posts: 14205
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: item 1+2

Post by Klaus » Mon May 26, 2014 4:36 pm

Hi Rob,
Why?
because the engine will first add 1 + 3 = 3 and deliver you item 3 (1+2) of it 8)
You need to use the & sign!
...
put item 1 of it && item 2 of it
...
&& will concatenate two strings with a SPACE between them!


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10335
Joined: Wed May 06, 2009 2:28 pm

Re: item 1+2

Post by dunbarx » Mon May 26, 2014 6:17 pm

Rob.

What Klaus said.

But it isn't the space that is important, it is what you wanted out of your original construction. Extracting two separate chunks from a string requires two separate chunk operations.

Imagine you had a return delimited list instead, and wanted the first and third line as a new list:

Fred
John
Harry

I bet you will see that the following is a tad wrongheaded (PseudoCode);

answer line 1 + 3

Fred
Harry

You would rather: answer line 1 & return & line 3

Craig Newman

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: item 1+2

Post by robm80 » Mon May 26, 2014 8:43 pm

Hi Klaus e.o.

Is there not an equivalent of put chars 1 to 6 of "abcdefghijklmn"
answer "abcdef"

or

get "Foo, John,Westerveen 29,9751 HT,HAREN,,,,,,de Heer en Mevrouw; "
or put items 1 to 3 of it
answer "Foo, John,Westerveen 29"

It could make scripting a bit easier....

Klaus
Posts: 14205
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: item 1+2

Post by Klaus » Mon May 26, 2014 10:10 pm

Hi Rob.

yes, you can:
...
put "Foo, John,Westerveen 29,9751 HT,HAREN,,,,,,de Heer en Mevrouw; " into tVar
put item 1 to 2 of tvar
## -> Foo, John
## Including the itemdelimiter, if that is what you want!
...


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10335
Joined: Wed May 06, 2009 2:28 pm

Re: item 1+2

Post by dunbarx » Tue May 27, 2014 2:14 am

What Klaus said again.

It is just a matter of getting used to the syntax. If you look back, you will see that simply (mentally and physically) replacing "+" with "to" is all it takes to make it all work.

Craig

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: item 1+2

Post by robm80 » Tue May 27, 2014 8:52 am

hi Klaus + Craig
Yes, changing the + to "to" is exactly I was looking for.
But where did I find that + ?: in "menus.rev" recommende by Klaus. BTW very interesting stuff all those rev's.

Klaus
Posts: 14205
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: item 1+2

Post by Klaus » Tue May 27, 2014 11:26 am

Hi Rob,

you mean in the "Menus" stack from teh scripting conferences?
Where exactly is this?

I just had alook at that stack and did not find any hint about
using + for concatenating strings.


Best

Klaus

Post Reply