IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesVB Classic  Print This     

String Concatenation (VB Classic and C++/CLI Cross Reference Guide)

By Mike Prestwood

VB Classic versus C++/CLI: A side by side comparison between VB Classic and C++/CLI.

 
Operators
 

A language symbol used for assignment, comparison, computational, or as a logical.

String Concatenation

[Other Languages] 
VB Classic:  "String Concatenation" & or +

Although you can use either a & or a + to concatenate values, my preference is to use a + because more languages use it. However, if you use & then some type conversions are done for you. If you use + you will sometimes have to cast a value to concatenate it. For example, you will have to use CStr to cast a number to a string if you use the + operator as a concatenation operator.

Syntax Example:
Dim FirstName As String
Dim LastName As String
 
FirstName = "Mike"
LastName = "Prestwood"
 
MsgBox "Full name: " & FirstName & " " + LastName
 
MsgBox "2+2=" + CStr(2+2)
C++/CLI:  "String Concatenation" +

C++/CLI performs implicit casting of numbers to strings. To concatenate two strings, a string to an integer, or a string to a floating point number, use the + operator. For example, to convert a floating point number to a string just concatenate an empty string to the number as in "" + 3.2.

Alternatively, you can use the System.Text.StringBuilder class which frequently but not always provides faster code.

Syntax Example:  
//Implicit casting of numbers.
//
//This fails:
//MessageBox::Show(3.3);
//
//This works:
MessageBox::Show("" + 3.3);












Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]