Home All Groups Group Topic Archive Search About
Author
29 Jun 2006 11:51 AM
Domac
What is the difference between "+" and "&" operator when joining strings?


Thanx!

Author
29 Jun 2006 12:09 PM
Herfried K. Wagner [MVP]
"Domac" <d*@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/>
Author
29 Jun 2006 12:19 PM
Ted Harrison
On Thu, 29 Jun 2006 13:51:07 +0200 Domac <d*@dd.cc> wrote:

> *From:* "Domac" <d*@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.
Author
29 Jun 2006 8:45 PM
Miro
Excellent Answer.

Short, sweet, and most important a simple example.

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

Miro
- Learning VB Net


Show quoteHide quote
"Ted Harrison" <t**@ntsx.co.uk> wrote in message
news:memo.20060629131952.384B@ed.eddy.ed...
> On Thu, 29 Jun 2006 13:51:07 +0200 Domac <d*@dd.cc> wrote:
>
>> *From:* "Domac" <d*@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.
>
Author
29 Jun 2006 12:43 PM
Domac
Thanks a lot!

Show quoteHide quote
"Domac" <d*@dd.cc> wrote in message
news:un%23SQJ3mGHA.732@TK2MSFTNGP04.phx.gbl...
> What is the difference between "+" and "&" operator when joining strings?
>
>
> Thanx!
>
>
>
Author
29 Jun 2006 1:10 PM
Phill W.
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.
Author
29 Jun 2006 3:02 PM
Brian Tkatch
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.
Author
29 Jun 2006 6:23 PM
Dick Sutton
I use &= in assignment statements all the time.  For example:

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

Hope this helps...

Dick

Show quoteHide quote
"Brian Tkatch" <Maxwell_Sm***@ThePentagon.com> wrote in message
news:1151593333.087137.67580@b68g2000cwa.googlegroups.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.
>
Author
29 Jun 2006 8:00 PM
Brian Tkatch
Dick Sutton wrote:
Show quoteHide quote
> 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" <Maxwell_Sm***@ThePentagon.com> wrote in message
> news:1151593333.087137.67580@b68g2000cwa.googlegroups.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.
Author
29 Jun 2006 11:40 PM
Göran_Andersson
Brian Tkatch wrote:
Show quoteHide quote
> 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" <Maxwell_Sm***@ThePentagon.com> wrote in message
>> news:1151593333.087137.67580@b68g2000cwa.googlegroups.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.
Author
30 Jun 2006 8:00 AM
guy
i dont know about myvar& not working but myvar% still does,
it still documented as working too

guy

Show quoteHide quote
"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" <Maxwell_Sm***@ThePentagon.com> wrote in message
> >> news:1151593333.087137.67580@b68g2000cwa.googlegroups.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.
>
Author
1 Jul 2006 7:06 PM
Jay B. Harlow [MVP - Outlook]
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


Show quoteHide quote
"Göran Andersson" <gu***@guffa.com> wrote in message
news:%23DGmuV9mGHA.3544@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" <Maxwell_Sm***@ThePentagon.com> wrote in message
| >> news:1151593333.087137.67580@b68g2000cwa.googlegroups.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.
Author
2 Jul 2006 6:08 PM
Göran_Andersson
Jay B. Harlow [MVP - Outlook] wrote:
Show quoteHide quote
> 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...
Author
29 Jun 2006 10:35 PM
Stuart Nathan
I can do &=