Info

rrr f

Figure 3-8. The VB 2008 & operator results in a call to String.Concat().

Given this, it is possible to perform string concatenation by calling String.Concat() directly (although you really have not gained anything by doing so, in fact you have incurred additional keystrokes!):

Module Program Sub Main()

Console.WriteLine("***** Fun with Strings *****")

Dim s1 As String = "Programming the " Dim s2 As String = "PsychoDrill (PTP)" Dim s3 As String = String.Concat(s1, s2)

Console.WriteLine(s3) End Sub End Module

On a related note, do know that the VB6-style string constants (such as vbLf, vbCrLf, and vbCr) are still exposed through the Microsoft.VisualBasic.dll assembly (see Chapter 2). Therefore, if you wish to concatenate a string that contains various newline characters (for display purposes), you may do so as follows:

Module Program Sub Main()

Console.WriteLine("***** Fun with Strings *****")

Dim s1 As String = "Programming the " Dim s2 As String = "PsychoDrill (PTP)" Dim s3 As String = String.Concat(s1, s2) s3 &= vbLf & "was a great industrial project." Console.WriteLine(s3) End Sub End Module

Note If you have a background in C-based languages, understand that the vbLf constant is functionally equivalent to the newline escape character (\n).

Was this article helpful?

0 0

Post a comment