Visual Basic .NET/String and character operators
From Wikibooks, the open-content textbooks collection
[edit] String Operator
[edit] String concatenation
The "&" operator joins two strings together. Example:
Dim String1 As String = "123" Dim String2 As String = "456" Dim String3 As String String3 = String1 & String2 ' Results in "123456".
This will result in String3 being equal to "123456"
The "+" operator may be used in place of "&". However, it is not recommended.
[edit] Concat
You may concatenate a number of strings:
Dim String1 As String = "Let" Dim String2 As String = " us" Dim String3 As String = " concatenate!" Dim strOutput As String
strOutput = String.concat(String1,String2,String3) ' Results in "Let us concatenate!".
If you have defined a string array, such as:
Dim strArr As String() = {"I", " am", " your", " automatic", " lover."}
then all the elements of this array may be concatenated in a simple way:
strOutput = string.concat(strArr) ' Results in "I am your automatic lover."