IT KNOWLEDGE

IT KNOWLEDGE
BC

Tuesday, May 20, 2014

Concatenate String (VB.Net)

Concatenate string is one operation which allow us to combine two or more string together. In Concatenate operation, there are two operators (+) / (&). The difference of these two operators are:

  • (+) Operator : the primary purpose of this operator is used to add two number, but we also can combine string too. (string1+string2+string3....)
  • (&) Operator: can use only with string and string(string1 & string2).
In this tutorial, I use 3 textboxes and combine string together by displaying in message box.

Application Design

No Control Type Name Text
1 Form1 FormConcatenate Concatenate String
2 Textbox1 TextboxString1
3 Textbox2 TextboxString2
4 Textbox TextboxString3
5 Button1 ButonPlus Concatenate(+)
6 Button ButonAnd Concatenate(&)




Code

Using (+) Operator
Private Sub ButtonPlus_Click(sender As Object, e As EventArgs) Handles ButtonPlus.Click
        string1 = TextBoxString1.Text
        String2 = TextBoxString2.Text
        string3 = TextBoxString3.Text
        MessageBox.Show("The Concatenate String using +      is :" & string1 + String2 + string3)

 End Sub




Using (&) Operator
Private Sub ButtonAnd_Click(sender As Object, e As EventArgs) Handles ButtonAnd.Click
        MessageBox.Show("The Concatenate String using +      is :" & string1 & "---" & String2 & "---" & string3)
    End Sub



Whole Code

Public Class FormConcatenate
    Dim string1 As String
    Dim String2 As String
    Dim string3 As String

    Private Sub ButtonPlus_Click(sender As Object, e As EventArgs) Handles ButtonPlus.Click
        string1 = TextBoxString1.Text
        String2 = TextBoxString2.Text
        string3 = TextBoxString3.Text
        MessageBox.Show("The Concatenate String using +      is :" & string1 + String2 + string3)
    End Sub

    Private Sub ButtonAnd_Click(sender As Object, e As EventArgs) Handles ButtonAnd.Click
        MessageBox.Show("The Concatenate String using +      is :" & string1 & "---" & String2 & "---" & string3)
    End Sub
End Class


According the sample code below show that, if you want to combine string with more customize, it's better to use (&).














































Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: itech-9999

0 comments: