TheSwamp
Code Red => VB(A) => Topic started by: LE on November 16, 2006, 11:30:22 PM
-
I am porting a code in VB to C++ and would like to know when or why a VB programmer use the concatenation operators + or & for the Strings...
Thanks!
-
It is mostly curiosity, since I noticed that in the VB code they are using &
i.e:
S1 = sTotalSize & StrReverse(sPath) & sTotalSize
I end up using CString and did:
S1 = sTotalSize + sPath.MakeReverse() + sTotalSize;
Thanks!
-
Good question, I've wondered that as well. & looks cooler though
-
No it is usefull.
With the ampersant (&) you will glue to strings to gether without any mathematical process of adding or subtracting.
The + can and will do an addition in certain circumstances. The danger lies especcially in variants because they can hold strings as well as Numeric data.
Imagine a street with a sligtly odd numbering system (due to ancient locaL customs)
in this street (oddstreet) houses are nubered 1 to100 but a appartment buiolding was build later in the middle with the numbers 50-1 to 50-80
It can happen you divide the numer and suffix in your database (pretty normal)
but if you retrieve those numbers into variants and put them together with the + houseumber 50 + -80 can become -30 because they were interpreted as two numbers to add up.
So the & is for adding string together and the + for adding numbers together.
-
Nice, Peanuts in order Berend
-
Thank you, it makes more sense now - !