16.3. String Constructors
Class String provides eight constructors for initializing Strings. Figure 16.1 demonstrates three of the constructors.
Figure 16.1. String constructors
1 ' Fig. 16.1: StringConstructor.vb 2 ' Demonstrating String class constructors. 3 4 Module StringConstructor 5 Sub Main() 6 Dim originalString, string1, string2, _ 7 string3, string4 As String 8 Dim characterArray() As Char = _ 9 {"b"c, "i"c, "r"c, "t"c, "h"c, " "c, "d"c, "a"c, "y"c} 10 11 ' string initialization 12 originalString = "Welcome to VB programming!" 13 string1 = originalString 14 string2 = New String(characterArray) 15 string3 = New String(characterArray, 6, 3) 16 string4 = New String("C"c, 5) 17 18 Console.WriteLine("string1 = " & """" & string1 & ... |
Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.