Expressions using string variables

VB.NET programs can use string variables as well as numeric variables. We have a program demonstrating the use of string variables.

The program begins by constructing three string variables called strA, strB, and strC:

The statements following the declarations display the values of expressions using the three variables. Like numeric expressions, string expressions are made up of operators and operands, and the operands may be variables or constants. Note that the concatenation operator can be either + or &.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Declare three string variables
        Dim strA As String = "Albert"
        Dim strB As String = "Bobby"
        Dim strC As String = "Charlie"

        ' Evaluate expressions and display results
        Label1.Text = strA
        Label2.Text = strB
        Label3.Text = strC
        Label4.Text = strA & strB
        Label5.Text = strA + strC
        Label6.Text = strB & " " & strC
        Label7.Text = strA & ", " & strB & ", and " & strC & " are friends."

    End Sub

The lengths of string variables is variable, and they can hold strings up to 2 billion characters long.


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.