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 3 3079
Mythran <ki********@hot mail.comREMOVET RAIL> 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.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Mythran" <ki********@hot mail.comREMOVET RAIL> 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.Ne wLine & "Goo"'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Mythran <ki********@hot mail.comREMOVET RAIL> 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.co m> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 something like
this:
1) e = (a, b, c, d); // concatenate a,b,c,d into e
2) (a, b, c, d) = e; // get the bits of e into a,b,c, and d
For example, in the second case, assume that a,b,c,d represent 2-bit
integers, and e represents an 8-bit...
|
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, 20-30k), what are the performance differences (if any
with something as trivial as this) between initializing a new instance of
StringBuilder with a specified capacity vs. initializing a new instance
without... (the final length is not fixed)
ie,
|
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 iam0.g_parentSequence || iam0.g_itemId || '/%'
SQL0440N No authorized routine named "||" of type "FUNCTION" having
compatible arguments was found. SQLSTATE=42884
|
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
|
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 e.Item.DataItem("Employer") <> ""
Then
Sections.Text += "<BR><B>Employer</B>: " & e.Item.DataItem("Employer")
End If
Is this an efficient way to build the section label's text property? Any
suggestions?
| |
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
|
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";
|
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.
____________
THE OVERVIEW
I don't remember where I picked it up, but I remember reading years
ago that the simple, obvious Python approach for string concatenation:
x = "a" + "b"
|
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 =
insuranceDataGridView.CurrentRow.Cells.FormattedValue.ToString();
string fileName = "0000000" +
Convert.ToString(Convert.ToDecimal(insuranceDataGridView.CurrentRow.Cells.FormattedValue.ToString())
/ 1000) + ".tif";
|
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,...
|
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...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |