Page 1 of 1

connect text strings

Posted: Thu Mar 07, 2024 11:58 am
by Walther
Hello, I am new an have a simple question:
what is the command that the same as
wert = wert + wert1 in other programming languages:
sample: the string wert has the value "a", wert1 has the value "b", wert is now "ab"
next step
wert = wert + wert1, wert now "abb" and so on

Re: connect text strings

Posted: Thu Mar 07, 2024 12:19 pm
by stam
Walther wrote:
Thu Mar 07, 2024 11:58 am
Hello, I am new an have a simple question:
what is the command that the same as
wert = wert + wert1 in other programming languages:
sample: the string wert has the value "a", wert1 has the value "b", wert is now "ab"
next step
wert = wert + wert1, wert now "abb" and so on
Hi - and welcome to LC.

The concatenation operator equivalent in LC is "&"
Note that "&&" introduces a space between concatenated items, so if a space is needed it does not need to be added to the variable or separately.
Other operators that concatenate : before, after
Typically the verb used is "put into|before|after" instead of the assignment operator "=".

For your example:

Code: Select all

put a into wert ; put b into wert1
put wert & wert1 into wert // wert now contains "ab"
put wert & wert1 into wert // wert now contains "abb"

// or alternatively for same result
put wert1 after wert 
Stam

Re: connect text strings

Posted: Thu Mar 07, 2024 3:00 pm
by dunbarx
Walther.

What Stam said.

The "&" operator becomes invaluable in certain situations. For example, if you want to create the string "a", and by that I mean that the quotes are part of that string, one can:

Code: Select all

on mouseUp
   put "a" into wert
   answer wert --just one character
   put quote & "a" & quote into wert
   answer wert --includes the appended and prepended quote characters
end mouseUp
Since "quote" is a constant in LC, the only way to make such a string is by using the "&" operator. You can see how the previous few lines of my text uses quotes to identify and isolate strings. This is different than having quotes embedded in those strings.

Craig

Re: connect text strings

Posted: Fri Mar 08, 2024 8:05 am
by Walther
Tank you very much. It works.
Walther

Re: connect text strings

Posted: Tue Mar 19, 2024 1:00 pm
by Klaus
Hi Walther,

welcome to the forum!

Sounds like you are german, there is also a german LC forum here:
https://www.livecode-blog.de/forums/for ... ode-forum/

Best

Klaus