NewBie's Corner Session 4 The Plus Sign and Concatenation Operators

NewBie's Corner Session 4 The Plus Sign and Concatenation Operators

Welcome to NewBie's Corner, a weekly or biweekly post covering basic Caché Material.

Click on the Caché Cube in your system tray and select Terminal to try out the commands.

Plus Sign (+) operator

Typically, the Plus sign (+) adds two numbers together. This is true in COS (Caché ObjectScript), but COS uses it in other ways as well.

Set the variable X to a value of +12

Set X=+12
Write X
12

Set the variable X to the value of +"ABC"

Set X=+"ABC"
Write X
0

Here, the Set command sets the variable X to +"ABC". Since X is not numeric, the plus sign forces X to be numeric, a zero.  In COS, the plus sign is used in many ways.

Set X="ABC"
Write +X
0
Write X                 ; The actual value of X does not change
ABC

So,

 if X="ABC" and +X=0,          

What does +"5ABC" yield?

If you answered 5 you are right, not 5000, but just 5

Then, what about X = "ABC5", what does +X yield?

Or what about X = "A5376", what does +X yield?

What about X = "", what does +X yield?

X = "—" ?

Concatenation Operator

Now, be careful not to confuse the Plus Sign operator with the Concatenation operator, the Underscore.

Set X="My dog's name is"
Set Y="Teddy."
Set DOG=X_" "_Y
Write DOG
My dog's name is Teddy.

As you can see, the underscore concatenated variables X and Y.

Until next time.

--Mike Kadow

PaulMikeKadow@gmail.com

If you have a comment, please respond through the InterSystems Developer Community, don't send me private email. Unless of course you wish to address me only.

See NewBie Index for an index of all NewBie Corner posts.

 

“It is not how much you know, but how well you communicate it to others.”

 

  • 0
  • 0
  • 220
  • 0