connect text strings

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
Walther
Posts: 2
Joined: Thu Mar 07, 2024 10:13 am

connect text strings

Post by Walther » 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

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: connect text strings

Post by stam » Thu Mar 07, 2024 12:19 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: connect text strings

Post by dunbarx » Thu Mar 07, 2024 3:00 pm

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

Walther
Posts: 2
Joined: Thu Mar 07, 2024 10:13 am

Re: connect text strings

Post by Walther » Fri Mar 08, 2024 8:05 am

Tank you very much. It works.
Walther

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: connect text strings

Post by Klaus » Tue Mar 19, 2024 1:00 pm

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”