Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenation operator

Status
Not open for further replies.

gymbeef

Technical User
Sep 18, 2002
33
US
When doing string concatenation, is there any practical difference between using + versus & ?
Anytime one should prefer one over the other, or not use one or the other?

thanks
 
The Ampersand(&) is defined as:
Used to force string concatenation of two expressions.

While the Addition(+) sign has numerious functions. It can be the same as Ampersand if both expressions are strings. Here are a couple of combinations and the way the operator acts:

String & String = cancatenation
String + String = cancatenation
Numeric + Numeric = addition
Numeric + Variant = addition

See ACCESS Help for the + operator for a complete definition of the other possibilities.

Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Hey gym,

Here's a basic difference:

?"01" + 1
yields: 2

?"01" & 1
yields 011

Looks like the "+" operator will attempt a data conversion with a prejudice to numeric, while "&" will do the same for string. Could make for some interesting bugs in a program.

I always use & for string concats.

Mike Pastore

Hats off to (Roy) Harper
 
In addition:

String & Null = String
String + Null = Null

You can use a combination if you have a primary and an optional secondary value to display a separator (such a line) between the values or just the primary value (without the separator) if secondary value does not exist.

PrimaryValue & ("-" + SecondaryValue)


HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top