473,770 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String.concat method in vb.net


Hi,

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

Why it do not refer to owner object so

tmpStr.Concat(t mpStr, tmpStr2)

and now tmpStr has same value as upper?

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

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

tmpStr = String.Concat(t mpStr, tmpStr2)

Why it do not refer to owner object so

tmpStr.Concat(t mpStr, 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(t mpStr2)

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******@hotma il.com> wrote in message
news:Op******** ******@TK2MSFTN GP10.phx.gbl...
:
: Hi,
:
: Concat wors as
: tmpStr = tmpStr.Concat(t mpStr, tmpStr2)
:
: Why it do not refer to owner object so
:
: tmpStr.Concat(t mpStr, tmpStr2)
:
: and now tmpStr has same value as upper?
:
: Regards, jacky
:
:
Nov 20 '05 #4
"Jacky" <ja******@hotma il.com> wrote in news:OpIbOdfgDH A.2084
@TK2MSFTNGP10.p hx.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*******@free net.de> schrieb:
Concat wors as
tmpStr = tmpStr.Concat(t mpStr, 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

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

Similar topics

2
39808
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 date variable in 'mm/dd/yyyy' or 'm/dd/yyyy' format. My code is shown below. Any suggestions? code: String sailYear = (String)sail_date.toString().substring(0,4);
3
11160
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
485
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 & c & d & e +/- 420ms
1
1924
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 if all are checked. But currently, just the last selection is going in. Here's the code I have:
3
3085
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" Dim c As String = a & b Dim d As String = String.Concat(a, b) string a = "bah"; string b = "bah2";
17
15329
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
7583
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 == : print """Concat: concatenates the arguments with a colon (:) between them
15
2608
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 both and I am wondewring if I should standardize or not ??
3
240
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 StringBuilder(); ad.AppendLine("<script type='text/javascript'>"); ad.AppendLine("<!--"); ad.AppendLine(String.Concat("google_ad_client = '", client,
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.