473,320 Members | 1,859 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,320 software developers and data experts.

Concatenation - String.Concat

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";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method when
the size/number of strings is unknown?

Thanks,
Mythran

Feb 6 '06 #1
3 1405
Mythran <ki********@hotmail.comREMOVETRAIL> wrote:
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";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method when
the size/number of strings is unknown?


They compile to the same code - the compiler uses String.Concat
internally. However, I believe that using the operator is usually more
readable than using string.Concat explicitly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 6 '06 #2
"Mythran" <ki********@hotmail.comREMOVETRAIL> schrieb:
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";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method
when


I suggest to use the '&' operator in the examples described above. This
will enable the compiler to concatenate string literals at compile time in
some cases such as '"Bla" & ControlChars.NewLine & "Goo"'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Feb 6 '06 #3

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Mythran <ki********@hotmail.comREMOVETRAIL> wrote:
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";
string c = a + b;
string d = string.Concat(a, b);

Like I said, doesn't really matter .. but sometimes I use one, and other
times I use the other. Is there a recommended one? Should I use the
concatenation operator (+/&) for small, known strings and Concat method
when
the size/number of strings is unknown?


They compile to the same code - the compiler uses String.Concat
internally. However, I believe that using the operator is usually more
readable than using string.Concat explicitly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Ok, thanks Jon.

Mythran

Feb 6 '06 #4

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

Similar topics

7
by: Paul Davis | last post by:
I'd like to overload 'comma' to define a concatenation operator for integer-like classes. I've got some first ideas, but I'd appreciate a sanity check. The concatenation operator needs to so...
37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
18
by: Larry Menard | last post by:
Is it not valid to use concatenation in a WHERE ... LIKE clause? SELECT iam0.g_itemId FROM g2_ItemAttributesMap AS iam0, g2_ItemAttributesMap AS iam1 WHERE iam1.g_parentSequence LIKE...
3
by: michael.martin | last post by:
Hi, I am wondering if something like this is possible? #define COLON ":" #define PERIOD "." #define WORD "word" #define WORD_COLON WORD+COLON
3
by: GM | last post by:
I am building the text for a resume section label in databinding with 20 or so data columns using a series of 20 or so code snippits like the following: If e.Item.DataItem("EmployerDisplay") And...
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...
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"...
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 ==...
34
by: Larry Hastings | last post by:
This is such a long posting that I've broken it out into sections. Note that while developing this patch I discovered a Subtle Bug in CPython, which I have discussed in its own section below. ...
5
by: Edwin Smith | last post by:
Hello: I have a problem building a file command line argument from 2 cells in a table with the following code. string filePath =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.