473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

+ and & operators

What is the difference between "+" and "&" operator when joining strings?
Thanx!

Jun 29 '06 #1
12 1228
"Domac" <dd@dd.cc> schrieb:
What is the difference between "+" and "&" operator when joining strings?


Did you already read the documentation on these operators?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jun 29 '06 #2
On Thu, 29 Jun 2006 13:51:07 +0200 Domac <dd@dd.cc> wrote:
*From:* "Domac" <dd@dd.cc>
*Date:* Thu, 29 Jun 2006 13:51:07 +0200

What is the difference between "+" and "&" operator when joining
strings?


Not much difference when joining two real strings.
"aaa" + "bbb" would give the same result as "aaa" & "bbb" i.e. "aaabbb"

However, if one expression is a number and one a string then things are
less clear...

"5" + 10 will give the number 15. The "5" is converted to a number "on the
fly".

Whereas "5" & 10 will give the string "510". The 10 is converted to a
string "on the fly".

+ should really only be used to add numbers, and & should be used to
concatenate strings.

Jun 29 '06 #3
Thanks a lot!

"Domac" <dd@dd.cc> wrote in message
news:un***************@TK2MSFTNGP04.phx.gbl...
What is the difference between "+" and "&" operator when joining strings?
Thanx!

Jun 29 '06 #4
Domac wrote:
What is the difference between "+" and "&" operator when joining strings?


With "Option Strict On" - none at all.

With "Option Strict Off" and joining only Strings - none at all.

With "Option Strict Off" and joining Strings and /other/ data types -
the effects can be "interesting" ...

HTH,
Phill W.
Jun 29 '06 #5

Phill W. wrote:
Domac wrote:
What is the difference between "+" and "&" operator when joining strings?


With "Option Strict On" - none at all.

With "Option Strict Off" and joining only Strings - none at all.

With "Option Strict Off" and joining Strings and /other/ data types -
the effects can be "interesting" ...

HTH,
Phill W.


Except that you can do += but not &=.

B.

Jun 29 '06 #6
I use &= in assignment statements all the time. For example:

strHTML &= MonthName(CInt(sMonth), False) & " - " & sYear &
"</h3></center><br>"

Hope this helps...

Dick

"Brian Tkatch" <Ma***********@ThePentagon.com> wrote in message
news:11*********************@b68g2000cwa.googlegro ups.com...

Phill W. wrote:
Domac wrote:
> What is the difference between "+" and "&" operator when joining
> strings?


With "Option Strict On" - none at all.

With "Option Strict Off" and joining only Strings - none at all.

With "Option Strict Off" and joining Strings and /other/ data types -
the effects can be "interesting" ...

HTH,
Phill W.


Except that you can do += but not &=.

B.

Jun 29 '06 #7
Dick Sutton wrote:
I use &= in assignment statements all the time. For example:

strHTML &= MonthName(CInt(sMonth), False) & " - " & sYear &
"</h3></center><br>"

Hope this helps...

Dick

"Brian Tkatch" <Ma***********@ThePentagon.com> wrote in message
news:11*********************@b68g2000cwa.googlegro ups.com...

Phill W. wrote:
Domac wrote:
> What is the difference between "+" and "&" operator when joining
> strings?

With "Option Strict On" - none at all.

With "Option Strict Off" and joining only Strings - none at all.

With "Option Strict Off" and joining Strings and /other/ data types -
the effects can be "interesting" ...

HTH,
Phill W.


Except that you can do += but not &=.

B.


OK, i see, my mistake. Thanks for the correction.

I quickly tested it out by opening a module and typing:

Sub a()
Dim a As String
a+=a
a&=a
End Sub

The editor separated a+=a into a += a, but it separated a&=a to a& = a
and underlined a& as an error. Which i assumed (incorrectly) that &=
was not supported.

So, perhaps a difference is whether the editor put in that space before
the operator. With = is does, with & it does not. Well, nothing too
important. :)

Thanx for the correction.

B.

Jun 29 '06 #8
Excellent Answer.

Short, sweet, and most important a simple example.

I didnt know why either, till i seen this post.

Miro
- Learning VB Net
"Ted Harrison" <te*@ntsx.co.uk> wrote in message
news:me**********************@ed.eddy.ed...
On Thu, 29 Jun 2006 13:51:07 +0200 Domac <dd@dd.cc> wrote:
*From:* "Domac" <dd@dd.cc>
*Date:* Thu, 29 Jun 2006 13:51:07 +0200

What is the difference between "+" and "&" operator when joining
strings?


Not much difference when joining two real strings.
"aaa" + "bbb" would give the same result as "aaa" & "bbb" i.e. "aaabbb"

However, if one expression is a number and one a string then things are
less clear...

"5" + 10 will give the number 15. The "5" is converted to a number "on the
fly".

Whereas "5" & 10 will give the string "510". The 10 is converted to a
string "on the fly".

+ should really only be used to add numbers, and & should be used to
concatenate strings.

Jun 29 '06 #9
Brian Tkatch wrote:
Dick Sutton wrote:
I use &= in assignment statements all the time. For example:

strHTML &= MonthName(CInt(sMonth), False) & " - " & sYear &
"</h3></center><br>"

Hope this helps...

Dick

"Brian Tkatch" <Ma***********@ThePentagon.com> wrote in message
news:11*********************@b68g2000cwa.googlegro ups.com...
Phill W. wrote:
Domac wrote:
> What is the difference between "+" and "&" operator when joining
> strings?
With "Option Strict On" - none at all.

With "Option Strict Off" and joining only Strings - none at all.

With "Option Strict Off" and joining Strings and /other/ data types -
the effects can be "interesting" ...

HTH,
Phill W.
Except that you can do += but not &=.

B.


OK, i see, my mistake. Thanks for the correction.

I quickly tested it out by opening a module and typing:

Sub a()
Dim a As String
a+=a
a&=a
End Sub

The editor separated a+=a into a += a, but it separated a&=a to a& = a
and underlined a& as an error. Which i assumed (incorrectly) that &=
was not supported.

So, perhaps a difference is whether the editor put in that space before
the operator. With = is does, with & it does not. Well, nothing too
important. :)

Thanx for the correction.

B.


That is Basic Baggage. The & character once had a meaning at the end of
a variable name. The interpreter still recognises this, but it doesn't
work any more.
Jun 29 '06 #10
guy
i dont know about myvar& not working but myvar% still does,
it still documented as working too

guy

"Göran Andersson" wrote:
Brian Tkatch wrote:
Dick Sutton wrote:
I use &= in assignment statements all the time. For example:

strHTML &= MonthName(CInt(sMonth), False) & " - " & sYear &
"</h3></center><br>"

Hope this helps...

Dick

"Brian Tkatch" <Ma***********@ThePentagon.com> wrote in message
news:11*********************@b68g2000cwa.googlegro ups.com...
Phill W. wrote:
> Domac wrote:
>> What is the difference between "+" and "&" operator when joining
>> strings?
> With "Option Strict On" - none at all.
>
> With "Option Strict Off" and joining only Strings - none at all.
>
> With "Option Strict Off" and joining Strings and /other/ data types -
> the effects can be "interesting" ...
>
> HTH,
> Phill W.
Except that you can do += but not &=.

B.


OK, i see, my mistake. Thanks for the correction.

I quickly tested it out by opening a module and typing:

Sub a()
Dim a As String
a+=a
a&=a
End Sub

The editor separated a+=a into a += a, but it separated a&=a to a& = a
and underlined a& as an error. Which i assumed (incorrectly) that &=
was not supported.

So, perhaps a difference is whether the editor put in that space before
the operator. With = is does, with & it does not. Well, nothing too
important. :)

Thanx for the correction.

B.


That is Basic Baggage. The & character once had a meaning at the end of
a variable name. The interpreter still recognises this, but it doesn't
work any more.

Jun 30 '06 #11
Göran
| That is Basic Baggage. The & character once had a meaning at the end of
| a variable name. The interpreter still recognises this, but it doesn't
| work any more.
As Guy suggests whatever& still works in both .NET 1.x & .NET 2.0.

For example:

Dim whatever&

is short hand for:

Dim whatever As Long

For details see:

http://msdn2.microsoft.com/en-us/library/s9cz43ek.aspx

However I don't recommend using it, as only a very small subset of types are
supported...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Göran Andersson" <gu***@guffa.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
| Brian Tkatch wrote:
| > Dick Sutton wrote:
| >> I use &= in assignment statements all the time. For example:
| >>
| >> strHTML &= MonthName(CInt(sMonth), False) & " - " & sYear &
| >> "</h3></center><br>"
| >>
| >> Hope this helps...
| >>
| >> Dick
| >>
| >> "Brian Tkatch" <Ma***********@ThePentagon.com> wrote in message
| >> news:11*********************@b68g2000cwa.googlegro ups.com...
| >>> Phill W. wrote:
| >>>> Domac wrote:
| >>>>> What is the difference between "+" and "&" operator when joining
| >>>>> strings?
| >>>> With "Option Strict On" - none at all.
| >>>>
| >>>> With "Option Strict Off" and joining only Strings - none at all.
| >>>>
| >>>> With "Option Strict Off" and joining Strings and /other/ data types -
| >>>> the effects can be "interesting" ...
| >>>>
| >>>> HTH,
| >>>> Phill W.
| >>> Except that you can do += but not &=.
| >>>
| >>> B.
| >>>
| >
| > OK, i see, my mistake. Thanks for the correction.
| >
| > I quickly tested it out by opening a module and typing:
| >
| > Sub a()
| > Dim a As String
| > a+=a
| > a&=a
| > End Sub
| >
| > The editor separated a+=a into a += a, but it separated a&=a to a& = a
| > and underlined a& as an error. Which i assumed (incorrectly) that &=
| > was not supported.
| >
| > So, perhaps a difference is whether the editor put in that space before
| > the operator. With = is does, with & it does not. Well, nothing too
| > important. :)
| >
| > Thanx for the correction.
| >
| > B.
| >
|
| That is Basic Baggage. The & character once had a meaning at the end of
| a variable name. The interpreter still recognises this, but it doesn't
| work any more.
Jul 1 '06 #12
Jay B. Harlow [MVP - Outlook] wrote:
Göran
| That is Basic Baggage. The & character once had a meaning at the end of
| a variable name. The interpreter still recognises this, but it doesn't
| work any more.
As Guy suggests whatever& still works in both .NET 1.x & .NET 2.0.

For example:

Dim whatever&

is short hand for:

Dim whatever As Long

For details see:

http://msdn2.microsoft.com/en-us/library/s9cz43ek.aspx

However I don't recommend using it, as only a very small subset of types are
supported...
Oh, so it still works, even?

Why didn't they get rid of that? They had the chance when they created
VB.NET, now it's gonna haunt the VB language for ever...
Jul 2 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jay Moore | last post by:
Greetings, all! I have a project for work, and I'm not sure how to efficiently do what I need to do. I'm hoping someone out there can help. Project is this: I'm creating a web-based...
8
by: Jef Driesen | last post by:
I'm implementing some image processing algorithms in C++. I created a class called 'image' (see declaration below), that will take care of the memory allocations and some basic (mathematical)...
27
by: ext_u | last post by:
Ok I thought I would try to take the program one thing at a time. (If you remember my last post I am trying to make a histogram with data on the size of each word) Anways first .. I obviously...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
17
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property ==...
16
by: Raterus | last post by:
I kinda just stumbled across these operators, they seem great, as you can forget the second expression depending on the result of the first, but are there any cons to using these? From my...
21
by: Mike | last post by:
I am having a problem getting AND to work. I have a MySQL database field defined as varbinary(8) with X00 in it. Then I have define statements with X01 in it. define('CERTACCESS_MEDALS', x01); ...
23
by: Hallvard B Furuseth | last post by:
As far as I can tell, (x & -1) is nonzero if the integer x is negative zero. So for signed types, x == 0 does not guarantee (x & foo) == 0. Is that right? (Not that I expect to ever encounter a...
7
by: Charles Law | last post by:
This is a very basic question, but I can' turn up a statement on the subject: In C#, if I have If (x == 1 && y == 2) { .... }
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.