473,406 Members | 2,293 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,406 software developers and data experts.

String.concat method in vb.net


Hi,

Concat wors as
tmpStr = tmpStr.Concat(tmpStr, tmpStr2)

Why it do not refer to owner object so

tmpStr.Concat(tmpStr, tmpStr2)

and now tmpStr has same value as upper?

Regards, jacky
Nov 20 '05 #1
16 7953
"Jacky" <ja******@hotmail.com> schrieb

Concat wors as
tmpStr = tmpStr.Concat(tmpStr, tmpStr2)
Concat is a shared member. The "better" syntax is:

tmpStr = String.Concat(tmpStr, tmpStr2)

Why it do not refer to owner object so

tmpStr.Concat(tmpStr, tmpStr2)

and now tmpStr has same value as upper?


I hope I know what you mean, but if I do, why don't you ask for this syntax:

tmpStr.Concat(tmpStr2)

Your version contains tmpStr twice.

The answer is that Strings are "immutable". Their content can not be
changed. Consequently, you must have the assignment like in your first
version.
--
Armin


Nov 20 '05 #2
Hi Jacky,

Overloads Public Shared Function Concat (String, String) As String

Being a Shared Function means that it belongs to the Class and is
available as
tmpStr = String.Concat (tmpStr, tmpStr2)

Instances can access their own methods and all the Class methods. Hence:
tmpStr = tmpStr.Concat (tmpStr, tmpStr2)

Accessing Concat using an instance of String is handy but, as you've
noticed, misleading, because the object is not acting in its own right but as
a representative of the Class.

Regards,
Fergus
Nov 20 '05 #3
Hi, the Concat method is shared, which means it cannot access the instance
data of the class it is contained within. It's logical that this is the case
because strings are immutable (take a look at MSDN). Basically, the data
cannot be changed, so when you do "change" the data, the instance is
destroyed and a new instance is created.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Jacky" <ja******@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP10.phx.gbl...
:
: Hi,
:
: Concat wors as
: tmpStr = tmpStr.Concat(tmpStr, tmpStr2)
:
: Why it do not refer to owner object so
:
: tmpStr.Concat(tmpStr, tmpStr2)
:
: and now tmpStr has same value as upper?
:
: Regards, jacky
:
:
Nov 20 '05 #4
"Jacky" <ja******@hotmail.com> wrote in news:OpIbOdfgDHA.2084
@TK2MSFTNGP10.phx.gbl:

Why it do not refer to owner object so


In addition to what the others said, also look into the StringBuilder
class.

Chris
Nov 20 '05 #5
Hello,

"Armin Zingler" <az*******@freenet.de> schrieb:
Concat wors as
tmpStr = tmpStr.Concat(tmpStr, tmpStr2)


Concat is a shared member. The "better" syntax is:


Better: "The syntax _I_ prefer is...".

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6
Hi Herfried,

It is actually 'better' for non-personal reasons. ;-)

From my post
|| Accessing Concat using an instance of String is handy but, as you've
|| noticed, misleading, because the object is not acting in its own right
|| but as a representative of the Class.

Regards,
Fergus
Nov 20 '05 #7
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
It is actually 'better' for non-personal reasons. ;-)

From my post
| Accessing Concat using an instance of String is handy but,
| as you've noticed, misleading, because the object is not
| acting in its own right but as a representative of the Class.


You are right. Nevertheless shared members can be seen as members of _all_
instances of the class, that's why they can be accessed through instance
members (that's impossible in C#).

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #8
Cor
Fergus Armin Herfried,
I doubt what the preferable methode is.
The so called "non better" method is so widely used, that it is become a
kind standard to use it. And therefore people do it ("Who did write most
people just copy code?)
Maybe it will in future be better to use the "better" method.
Therefore, when I am writing advices here in future, I shall use the Armin
and Fergus "better" method.
Cor
Nov 20 '05 #9
Good morning, Cor,

I think many people use it because it's shown by Intellisense and they
don't realise/notice/care that it's a class member. I'm sure I'm guilty of
that at times.It <does> have the potential to mislead, though, as it did with
Jacky. Perhaps Intellisense could be cleverer and insert the class name (as an
optional, of course).

Regards,
Fergus
Nov 20 '05 #10
Cor
Herfried,
Did send this wrong
It was for my message to Fergus,
Better: "The syntax _I_ prefer is...".


This is what I prefer to use in future too.
I shall try to remember it.

Cor

Nov 20 '05 #11
Cor
Herfried,
Better: "The syntax _I_ prefer is...".


This is what I prefer to use in future too.
I shall try to remember it.

Cor

Nov 20 '05 #12
Hello,

"Cor" <no*@non.com> schrieb:
Did send this wrong
It was for my message to Fergus,
Better: "The syntax _I_ prefer is...".


This is what I prefer to use in future too.
I shall try to remember it.


I prefer it too, nevertheless calling _shared_ members by using an instance
variable _makes sense_.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #13
Cor
Hi Herfried,
Better: "The syntax _I_ prefer is...".
This is what I prefer to use in future too.
I shall try to remember it.


I prefer it too, nevertheless calling _shared_ members by using an

instance variable _makes sense_.


Both answers where right, but I prefer to use the words "I prefer" instead
of "Better is" in future,
that fits better to VB.net., "Better is" fits in my opinion more for C#

:-)
Cor
Nov 20 '05 #14
You do know that you can Import(s) a class and access it's instance
members...

///
Imports System.Threading.Thread

..
..
..
Sleep(5000)
..
..
..
///

Cool.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:#g**************@TK2MSFTNGP09.phx.gbl...
: Hello,
:
: "Cor" <no*@non.com> schrieb:
: > Did send this wrong
: > It was for my message to Fergus,
: >
: > > Better: "The syntax _I_ prefer is...".
: >
: > This is what I prefer to use in future too.
: > I shall try to remember it.
:
: I prefer it too, nevertheless calling _shared_ members by using an
instance
: variable _makes sense_.
:
: --
: Herfried K. Wagner
: MVP · VB Classic, VB.NET
: http://www.mvps.org/dotnet
:
:
Nov 20 '05 #15
Hello,

"Tom Spink" <th**********@ntlworld.com> schrieb:
You do know that you can Import(s) a class and access
it's instance members...

///
Imports System.Threading.Thread

.
.
.
Sleep(5000)
.
.
.
///

Cool.


'Sleep' is a shared member of 'Thread'.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #16
Exactly....

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:ep**************@TK2MSFTNGP10.phx.gbl...
: Hello,
:
: "Tom Spink" <th**********@ntlworld.com> schrieb:
: > You do know that you can Import(s) a class and access
: > it's instance members...
: >
: > ///
: > Imports System.Threading.Thread
: >
: > .
: > .
: > .
: > Sleep(5000)
: > .
: > .
: > .
: > ///
: >
: > Cool.
:
: 'Sleep' is a shared member of 'Thread'.
:
: --
: Herfried K. Wagner
: MVP · VB Classic, VB.NET
: http://www.mvps.org/dotnet
:
:
Nov 20 '05 #17

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

Similar topics

2
by: Hector A | last post by:
Hi I'm trying to convert a string that already looks like a date to a date that I can use when I pass it from java to the database. I receive the date in format yyyy-mm-dd and I need it to be a...
3
by: John Ford | last post by:
For simple string concatenation, is there a difference between... Dim s As String s += "add this to string" ....and... Dim s As String s = String.Concat(s, "add this to string")
3
by: Dominique Vandensteen | last post by:
after the very small & vs string.format discussion I did some speed tests... loop of 1.000.000 concatenations of 5 public string variables in a class gave following results: result = a & b...
1
by: Trint Smith | last post by:
Ok, I have a webform that has these checkboxes: 1. something 2. something else 3. and something else When the user clicks on the checkbox, I want all of the selections to go into a textbox...
3
by: Mythran | last post by:
Out of curiosity, only, which is recommended for SHORT concatenation...or concatenating two or three strings that are relatively small in size? Dim a As String = "bah" Dim b As String = "bah2"...
17
by: ramadu | last post by:
I know its a sin to use strings, lets skip that part... Which of these is faster and uses less memory? String.Format("SomeValue='{0}'", m_Value); or String.Concat("SomeValue='", m_Value,...
7
by: Leonel Gayard | last post by:
Hi all, I had to write a small script, and I did it in python instead of shell-script. My script takes some arguments from the command line, like this. import sys args = sys.argv if args ==...
15
by: James | last post by:
Which is better, which is faster, which is easier etc... ????? String.Format ( "yadda {0} yadda {1}", x, y ) "yadda" + x.ToString() + " yadda" + y.tostring(); My code has a mish mash of...
3
by: shapper | last post by:
Hello, I have an Action where I define a ViewData property named Ad: public ActionResult GoogleAdSense(string client, int height, string slot, int width) { StringBuilder ad = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.